题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s=in.next(); if(s==null){ return; } int len=s.length(); int num=len%8; StringJoiner sj=new StringJoiner(""); // 将字符串补齐为能长度能被8整除的字符串 if(num!=0){ sj.add(s); sj.add("00000000".substring(num,8)); s=sj.toString(); } int i=0; // 对字符串进行截取,获得长度为8的子字符串 while((i+1)*8<=s.length()){ int start=i*8; int end=(i+1)*8; System.out.println(s.substring(start,end)); i++; } } }#字符串拼接#