•连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组;
•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。
思路,去空格,然后末尾补0,再输出
package com.java.huawei;
import java.util.Scanner;
/**
* @author dengtiantian
*/
public class Test3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
String str = sc.nextLine();
str = str.replace(" ","");
int temp = 8-(str.length()%8);
if (temp < 8){
for(int i = 0;i<temp;i++){
str+="0";
}
}
temp = str.length()/8;
for(int i = 0;i<temp;i++){
String s = str.substring(i*8,i*8+8);
System.out.println(s);
}
}
}
}