题解 | #java#小试牛刀

字符串分隔

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

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String str = scanner.nextLine();
            int b = str.length() / 8;
            int a = str.length() % 8;
            String c = "00000000";
            if (b > 0) {
                for (int i = 0; i < b; i++) {
                    System.out.println(str.substring(i * 8, 8 * (i + 1)));
                }
                if (a != 0) {
                    System.out.println(str.substring(str.length() - a, str.length()) + c.substring(a, 8));
                }
            }else {
                System.out.println(str.substring(str.length() - a, str.length()) + c.substring(a, 8));
            }
        }
    }

}
全部评论

相关推荐

点赞 评论 收藏
分享
Noob1024:一笔传三代,人走笔还在
点赞 评论 收藏
分享
点赞 1 评论
分享
牛客网
牛客企业服务