题解 | HJ4 字符串分隔
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7?tpId=37&tqId=21227&rp=1&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
StringBuilder sb = new StringBuilder(s);
// 补足后按8个一切
while (sb.length() % 8 != 0) {
sb.append('0');
}
// 每8个字符输出
for (int i = 0; i < sb.length(); i = i + 8) {
System.out.println(sb.substring(i, i + 8));
}
}
}

查看9道真题和解析