题解 | #字符串分隔#

字符串分隔

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

最少代码解法

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        fun4();
    }
    public static void fun4() {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(input);
        if (input.length() % 8 > 0) {
            for (int i = 0; i < 8 - input.length() % 8; i++) {
                stringBuilder.append("0");
            }
        }
        int index = 0;
        for (int j = 0; j < stringBuilder.length() / 8; j++) {
            String substring = stringBuilder.substring(index, index + 8);
            System.out.println(substring);
            index += 8;
        }
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务