题解 | 字符串分隔
字符串分隔
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);
String sts = in.nextLine();
char[] chc = sts.toCharArray();
String res = "";
for (int i = 0; i < chc.length; i++) {
res += chc[i];
if (res.length() == 8) {
System.out.println(res);
res = "";
}
}
if (res.length() != 0 && res.length() < 8) {
System.out.print(res);
for (int i = 0; i < 8 - res.length() ; i++) {
System.out.print(0);
}
}
}
}

查看14道真题和解析
海康威视公司氛围 916人发布