우당탕탕 자바 with 혼자 공부하는 자바

백준 11022 자바 - A + B의 최종 최최종 최최최종 버전!

hyxndy 2022. 3. 21. 21:48

백준 11022번 - A+B-8 with Java

https://www.acmicpc.net/problem/11022

 

11022번: A+B - 8

각 테스트 케이스마다 "Case #x: A + B = C" 형식으로 출력한다. x는 테스트 케이스 번호이고 1부터 시작하며, C는 A+B이다.

www.acmicpc.net

package BOJ1008;
import java.util.Scanner;

public class BOJ11022 {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for(int i = 1; i <= N; i++) {
			int A = sc.nextInt(); int B = sc.nextInt();
			System.out.print("Case #"+i+": ");
			System.out.print(A+" + "+B+ " = "+(A+B));
			System.out.println();
		}
	}

}

System.out.println() 함수를 이용해 위에 적힌 System.out.print 코드들을 한번에 출력해낼 수 있지만,

가독성을 높이기 위해 여러 줄로 작성해주었다.

System.out.print()는 줄바꿈 없이 printing해주는 함수이다.

다음 코드를 진행해주어도 줄이 바뀌지 않고 같은 줄에서 코드가 출력된다.

System.out.println()함수는 코드 출력과 동시에 줄이 바뀐다.

그래서 다른 작업을 하지 않고도 다음 코드가 다음 줄에 출력된다.


개인적으로 for문은 파이썬보다 자바가 더 쉬운 것 같다.

언넝 도서관에서 자바 책을 가져와서 다음 파트도 진행해야하는데..!!! 내일 도서관 가서 가져와야짓