题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
import java.io.*; public class Main { public static void main(String[] args) throws IOException{ BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); String str=null; while((str=br.readLine())!=null){ StringBuilder sb=new StringBuilder(str); int n=str.length();//字符串长度 while(n%8!=0){//加0使之成为8的倍数 sb.append("0");//尾部加0 n++;//加到8的位数为止 } for(int i=0;i<n;){//分组依次输出 String child=sb.substring(i,i+8);//拆分字符串 i=i+8; System.out.println(child);//输出 } } } }