题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); StringBuilder batch; int index = 0; /* * 若接下去截取的长度大于等于8,则说明不需要补位 */ while (index < str.length()) { if (str.substring(index).length() >= 8) { batch = new StringBuilder(str.substring(index, index + 8)); System.out.println(batch); } else { batch = new StringBuilder(str.substring(index)); for (int i = 0; i < 8 - (str.length() - index); i++) { batch.append("0"); } System.out.println(batch); } index += 8; } } }