题解 | #字符串分隔#

字符串分隔

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

import java.util.Scanner;

public class Main {
/*
*This is a solution by using Java language implement.
*@Author ChrisJohnson 
*@Email:chrisjohnsoncode@outlook.com
*@Algorithm description(by using nature language-English)
*Divided into two situations, if it is greater than 8, it will be intercepted in loop, and if it is *less than 8, it will be intercepted after zero padding in loop.
*/
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String string=in.nextLine();
        while(string.length()>8){
            System.out.println(string.substring(0,8));
            string=string.substring(8);
        }
        if(string.length()>0){
            string=string+"0000000";
            System.out.println(string.substring(0,8));
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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