-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem118.java
More file actions
29 lines (27 loc) · 864 Bytes
/
Copy pathProblem118.java
File metadata and controls
29 lines (27 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package basic;
import java.util.Scanner;
public class Problem118 { // 입력된 문자를 3개씩 쪼개서 합한 값 출력은 완료. 쪼갠 문자들을 출력하는데서 오류났었음
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String str1 = str.replaceAll(" ", "");
System.out.println(str1);
int count=0;
int sum=0;
String[] arr = str.split(" ", 3);
for(String data : arr)
System.out.print(data + " ");
System.out.println();
while(count < str1.length() - 3) {
sum += Integer.parseInt(str1.substring(count, count+3));
count += 3;
}
sum += Integer.parseInt(str1.substring(count, str1.length()));
for(int i=0; i<arr.length; i++) {
if(i == arr.length)
System.out.println(arr[i] + " = " + sum);
System.out.print(arr[i] + " + ");
}
sc.close();
}
}