5개의 정수를 입력받아 모두 붙여서 문자열로 저장한 후 세 자씩 나누어서 출력하는 프로그램을 작성하시오.
12 5963 58 1 45678
125
963
581
456
78
package com.jungol.algorithm190;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
StringBuilder sb = new StringBuilder();
Scanner sc = new Scanner(System.in);
int cnt = 0;
int reminderSstart = 0;
for(int i = 0; i < 5; i++) {
sb.append(sc.next());
}
while(true) {
//6, 9, 12 ...
if(cnt == sb.length() && sb.length() % 3 == 0) {
for(int i = 0; i < sb.length() / 3; i++) {
System.out.println(sb.substring(3 * i, 3 * i + 3));
}
break;
}
//5, 7, 8, 10, 11 ...
if(cnt == sb.length() && sb.length() % 3 != 0) {
for(int i = 0; i < sb.length() / 3; i++) {
System.out.println(sb.substring(3 * i, 3 * i + 3));
reminderSstart = 3 * i + 3;
}
System.out.println(sb.substring(reminderSstart));
break;
}
if(cnt == sb.length()) {
break;
}
cnt++;
}
sc.close();
}
}