题解 | #字符串分隔#

字符串分隔

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++;
        }
    }
}

#字符串拼接#
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 15:37
点赞 评论 收藏
分享
06-26 15:33
青岛工学院 Java
积极的秋田犬要冲国企:他现在邀请我明天面试
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-11 17:10
什么素质,我请问呢,要掉小珍珠了。。。又憋屈又生气
苍蓝星上艾露:给它们能的,一群dinner牛马挥刀向更弱者罢了。我写的开源求职AI co-pilot工具,优化你的简历,找到你匹配的岗位,定制你的简历,并让你做好面试准备https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务