题解 | #明明的随机数#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<String> string_list = new ArrayList<>();
while(scan.hasNext()){
String input = scan.nextLine();
if(input.length()>8){
StringBuffer temp = new StringBuffer();
for(int j=0; j<input.length();j++){
if(input.charAt(j)!='\0'){
temp.append(input.charAt(j));
}
if((j+1)%8==0){
string_list.add(temp.toString());
if(j<input.length())
temp= new StringBuffer();
}
}
if(temp!=null&&temp.length()!=0){
string_list.add(temp.toString());
}
}else
string_list.add(input);
}
for (int i = 0; i < string_list.size(); i++) {
int contain = string_list.get(i).length()%8;
int rest = 8 - contain;
// System.out.println("rest="+ rest);
if(string_list.get(i).length()==8)
System.out.println(string_list.get(i));
else{
StringBuffer temp = new StringBuffer();
for(int j=0; j<rest;j++){
temp.append("0");
}
System.out.println(string_list.get(i)+temp);
}
}
}
}