题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
String str = sc.nextLine();
int addZero = 8 - str.length() % 8;
// 输出个数(不包括剩余的那个)
int num = str.length() / 8;
int startIndex = 0;
for(int i = 0;i < num;i++){
System.out.println(str.substring(startIndex,startIndex+8));
startIndex += 8;
}
if(addZero > 0 && addZero < 8){
StringBuilder sb = new StringBuilder(str.substring(startIndex,str.length()));
for(int i = 0;i < addZero;i++){
sb.append('0');
}
System.out.println(sb.toString());
}
}
}
}