連續輸入字符串(輸出次數爲N,字符串長度小於100),請按長度爲8拆分每個字符串後輸出到新的字符串數組,
長度不是8整數倍的字符串請在後面補數字0,空字符串不處理。
首先輸入一個整數,爲要輸入的字符串個數。
public static void main(String[] args) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String input;
while ((input = bufferedReader.readLine()) != null) {
int count=Integer.parseInt(input);
StringBuilder result = new StringBuilder();
for(int i=0;i<count;i++) {
input=bufferedReader.readLine();
int start=0;
int end = 8;
int length = input.length() / 8;
if(input.length() % 8 > 0) {
++length;
}
for(int j = 0 ; j < length ; j ++) {
end = end > input.length() ? input.length() : end;
String current = input.substring(start, end);
result.append(current);
if(current.length() < 8) {
for(int k = 0 ; k < 8 - current.length() ; k ++) {
result.append("0");
}
}
result.append("\n");
start += 8;
end += 8;
}
}
}
}
}