题解 | #字符串分隔#

字符串分隔

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 str = in.next();
        while (str.length() > 8) {
            //因为是要8的倍数,所以到7就可以了
            System.out.println(str.substring(0, 8));
            //将原字符串截断
            str = str.substring(8);
        }
        if (str.length() == 8) {
            System.out.println(str);
        } else {
            //不能直接使用str.length(),因为str的长度会不断变化
            int n = str.length();
            for (int i = 0; i < 8 - n; i++) {
                str = str + "0";
            }
            System.out.println(str);
        }

    }
}

如代码所写

全部评论

相关推荐

白火同学:大二有这水平很牛了,可以适当对关键信息加粗一点,比如关键技术、性能指标之类的。
点赞 评论 收藏
分享
04-18 15:58
已编辑
门头沟学院 设计
kaoyu:这一看就不是计算机的,怎么还有个排斥洗碗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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