题解 | #字符串分隔#

字符串分隔

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

主要使用substring()方法,8个8个的分割字符串,最后剩下的做尾巴+0处理
public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String str=sc.nextLine();
        int len=str.length();
        int i=len;
        int j=0;
        while(i>8){
            System.out.println(str.substring(j,j+8));
            j+=8;
            i-=8;
        }
        System.out.println(Main.giveZero(str.substring(len-i,len)));
    }
    
    public static String giveZero(String str){
        int i=8-str.length();
        while(i>0){
            str+="0";
            i--;
        }
        return str;
    }


全部评论

相关推荐

头像
2025-12-27 13:01
三峡大学 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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