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