题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
while (sc.hasNextLine()){
String str = sc.nextLine();//输入字符串
// 调用切割方法
split(str);
}
}
public static void split(String str){
while(str.length()>=8){
System.out.println(str.substring(0,8));
str=str.substring(8);
}
if(str.length()0){
str+="00000000";
System.out.println(str.substring(0,8));
}
}
此方法是copy别人的 只说一下我发现的一个小小的注意点
只能使用hasNaxt()方法 和 nextLine()方法 否则无法处理字符串中的空格
查看18道真题和解析
vivo公司福利 364人发布