• Home
  • About
    • ming photo

      ming

      studying

    • Learn More
    • Twitter
    • Facebook
    • Instagram
    • Github
    • Steam
  • Archive
    • All Posts
    • All Tags
    • All categories
  • categories
    • HTML+CSS+JavaScript
    • JAVA
    • Algorithm
    • DB
    • JSP
    • 정보처리기사
    • Spring
    • Thymeleaf
    • 기술면접
  • Projects

BackJoon-11022-for

07 Feb 2021

BackJoon_11022

🎈 문제 링크

▶ JAVA 코드

import java.util.*;
public class for_11022 {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in); // 입력 클래스 Scanner 객체 생성
		int t = sc.nextInt(); // 입력값을 변수 t에 저장
		int a = 0;
		int b = 0;
		int count = 0;
		
		for(int i=1; i<=t; i++) { // i가 t의 값보다 작거나 크다면 1씩 증가하면서 반복한다
			a = sc.nextInt();
			b = sc.nextInt();
			count++;
			System.out.printf("Case #%d: %d + %d = %d%n",count,a,b,a+b);
		}

	}

}


▶ 코드 설명

1) 입력받을 Scanner 객체 생성
2) 입력받을 변수 t 생성
3) 반복문 : i는 t보다 작거나 같으면 t의 값만큼 1씩 증가하며 a,b변수에 입력받은 값을 저장하고 반복할때마다 반복횟수를 count변수에 저장한다

▶ 출력 결과창(Console) for_11022



Share Tweet +1