题解 | #字符串分隔#

字符串分隔

https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
       public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str = sc.nextLine();
            int number = 8 - str.length() % 8;
            StringBuilder stringBuilder = new StringBuilder();
            do {
                if (str.length() >= 8) {
                    for (int i = 0; i < 8; i++) {
                        System.out.print(str.charAt(i));
                    }
                    System.out.println();
                    if (str.length() == 8) {
                        str = "";
                    } else {
                        str = str.substring(8);
                    }
                } else {
                    stringBuilder.append(str);
                    for (int i = 0; i < number; i++) {
                        stringBuilder.append("0");
                    }
                    str = "";
                    System.out.println(stringBuilder.toString());
                }
            } while (str.length() != 0);

        }

    }

}

全部评论

相关推荐

刘湘_passion:出国旅游?那就小心你的腰子咯
点赞 评论 收藏
分享
04-29 22:35
门头沟学院 Java
牛友说改了名字能收到offer:旧图新发查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务