题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String str = sc.nextLine(); int number = 8 - str.length() % 8; StringBuilder stringBuilder = new StringBuilder(); do { if (str.length() >= 8) { for (int i = 0; i < 8; i++) { System.out.print(str.charAt(i)); } System.out.println(); if (str.length() == 8) { str = ""; } else { str = str.substring(8); } } else { stringBuilder.append(str); for (int i = 0; i < number; i++) { stringBuilder.append("0"); } str = ""; System.out.println(stringBuilder.toString()); } } while (str.length() != 0); } } }