Java/백준알고리즘
[Java] 백준알고리즘 #10953 A + B - 6
Sehyeok20
2023. 9. 27. 15:23
반응형
각 케이스의 두 수를 더한 값을 출력하는 문제.
코드는 다음과 같다.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
String[] testcase = new String[t];
for (int i = 0; i < t; i++) {
testcase[i] = sc.next();
String a[] = new String[2];
a = testcase[i].split(",");
int sum = Integer.parseInt(a[0]) + Integer.parseInt(a[1]);
System.out.println(sum);
}
sc.close();
}
}
두 문자를 split함수를 이용해 콤마(,)를 기준으로 나눈 후 크기 2인 배열에 저장.
이후는 배열에 저장된 수들을 Int형으로 파싱 후 더하면 끝
반응형