题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
import java.util.Scanner; public class Main { public static void main(String[] args) { // 1.接收输入的字符串 Scanner in = new Scanner(System.in); String str = in.nextLine(); split(str); } public static void split(String str){ // 如果字符串长度大于等于8就截取,一直循环 while(str.length()>=8){ System.out.println(str.substring(0,8)); str = str.substring(8); } // 字符串长度小于8 if(str.length()>0 && str.length()<8){ str+= "00000000"; System.out.println(str.substring(0,8)); } } }