PS/inflearn java coding
10953
easy16
2022. 4. 23. 10:21
Tip) sc.next() vs sc.nextLine()
nextLine으로 입력을 받을 경우, 5 이후 공백문자가 입력됨
따라서 split 할 때, 오류가 발생함.(주의)
5 => 개행을 nextLine 으로 입력받음
1,1
2,3
3,4
9,8
5,2
import java.util.Scanner;
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) {
String s = sc.next();
String []tmp = s.split(",");
System.out.println(Integer.parseInt(tmp[0]) + Integer.parseInt(tmp[1]));
}
}
}