매일코테
백준 3단계 no.7
공주맛밤
2022. 7. 20. 11:31
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i<n; i++) {
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println("Case #"+(i+1)+": "+(a+b));
}
}
}
<오답>
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i<n; i++) {
String a = sc.next();
String[] str = a.split(" ");
System.out.println("Case #"+(i+1)+": "+(Integer.parseInt(str[0])+Integer.parseInt(str[1]))
}
}
"1 2"와 같은 문자열을 .split(" ")하면 배열의 크기가 1이고 요소값이 1인 배열이 생성되는데 이유를 모르겠음
728x90
반응형