按长度为8拆分每个字符串后输出到新的字符串数组,长度不是8整数倍的字符串请在后面补数字0,空字符串不处理
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int count = 0;
String[] strings = null;
int index = 0;
while (scanner.hasNext()){
if(count == 0){
count = scanner.nextInt();
if(count <= 0 ){
System.out.println("程序结束");
return;
}
strings = new String[count];
}else {
String next = scanner.next();
strings[index] = next;
index++;
if(index == count){
break;
}
}
}
calc(strings);
}
private static void calc(String[] arr) {
List<String> list = new ArrayList<>(arr.length);
for (String s : arr) {
if(s == null || "".equals(s)){
continue;
}
if(s.length() < 8){
list.add(s);
}else {
int count = s.length() / 8;
if((s.length() % 8) != 0 ){
count++;
}
for (int i = 0; i < count; i++) {
String t = s.substring(i * 8 , Math.min(s.length(),(i + 1) * 8));
list.add(t);
}
}
}
for (String s : list) {
if(s.length() < 8){
int zoreCount = 8 - s.length();
for (int i = 0; i < zoreCount; i++) {
s+="0";
}
System.out.println(s);
}else {
System.out.println(s);
}
}
}