题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner fzhinput = new Scanner(System.in); String zfc = fzhinput.nextLine(); int length1; StringBuilder modifyzfc = new StringBuilder(); StringBuilder sczfc = new StringBuilder(); if (zfc.length()%8==0){ length1=zfc.length(); modifyzfc.append(zfc); } else{ length1=zfc.length()+8-zfc.length()%8; modifyzfc.append(zfc); for(int i = 0; i<8-zfc.length()%8 ; i++){ modifyzfc.append(0); } } for(int i=0; i<length1 ; i++){ char c = modifyzfc.charAt(i); sczfc.append(c); if((i+1)%8==0){ System.out.println(sczfc); sczfc.setLength(0); } } } }