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

내 답안 - 1
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(System.in);
int A = s.nextInt();
int B = s.nextInt();
while((A!=0) && (B!=0)) {
System.out.println(A+B);
A = s.nextInt();
B = s.nextInt();
}
}
}
정답처리가 되긴 했지만 A, B 입력받는 코드가 중복되어 들어가서 지저분하다는 생각에 다른 답안도 연구해보았다.
내 답안 - 2
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(System.in);
while(true) {
int A = s.nextInt();
int B = s.nextInt();
if ((A==0) && (B==0)) {
break;
}
System.out.println(A+B);
}
}
}
훨씬 깔끔해졌다.
'Coding Test > 백준' 카테고리의 다른 글
[백준 10818번 - java] 최소, 최대 (0) | 2021.11.08 |
---|---|
[백준 1110번 - java] 더하기 사이클 (0) | 2021.11.04 |
[백준 10871번 - java] X보다 작은 수 (0) | 2021.11.04 |
[백준 2439번 - java] 별찍기 - 2 (0) | 2021.11.04 |
[백준 2438번 - java] 별 찍기 - 1 (0) | 2021.11.04 |