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]));
}
}
}
'PS > inflearn java coding' 카테고리의 다른 글
최대점수구하기(냅색) (0) | 2022.04.14 |
---|---|
동전교환 (냅색) (0) | 2022.04.14 |
최대길이증가수열 (0) | 2022.04.14 |
계단오르기 (0) | 2022.04.14 |
원더랜드 (최소스패닝트리) (0) | 2022.04.14 |