题解 | #字符串分隔#
字符串分隔
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 sc=in.nextLine(); while(sc.length()>8) { System.out.println(sc.substring(0,8)); sc= sc.substring(8); } sc+="00000000"; System.out.println(sc.substring(0,8));} }
首先借鉴了别人的思路,无论是否大不大于8,最终都需要进行填零。所以用个循环进行限制,再在最后加上补零