题解 | #字符串分隔#

字符串分隔

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

import java.util.Scanner;
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int len = s.length();
        int num=len/8;//整串个数
        int modnum=len%8;//最后需要补全的串
        int i;
        for(i=0;i<num;i++)
        {
            System.out.println(s.substring(i*8,(i+1)*8));
        }

        if(modnum!=0)
        {
            String ss="0";
            for(int j=0;j<8-modnum-1;j++) ss+="0";//不知道为什么,用了repeat方法会报错
            String rst=s.substring(i*8)+ss;
            System.out.println(rst);
        }
    }
}

全部评论

相关推荐

06-10 23:36
已编辑
首都经济贸易大学 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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