题解 | #字符串分隔#

字符串分隔

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextLine()){
            String input = scanner.nextLine();
            int zeroLength = 8 - input.length() % 8;
            StringBuilder sb = new StringBuilder();
            sb.append(input);
            while(zeroLength > 0 && zeroLength < 8){
                sb.append("0");
                zeroLength--;
            }
            String result = sb.toString();
            while(result.length() > 0){
                System.out.println(result.substring(0,8));
                result = result.substring(8);
            }
            }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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