题解 | #字符串分隔#

字符串分隔

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

这个题主要是要细心。
定义变量的作用域要注意就可以。


import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
      Scanner in = new Scanner(System.in);
       String str = in.nextLine();
      String str2 = str;
        int len=8-str.length()%8;

       for(int i=0;i<len&&len!=8;i++)
       {
          str = str.concat("0");  
           
      }
        int max=str.length()/8;
        for(int j=0;j<max;j++){
                str2 = str.substring(8*j,8*(j+1));
               if(str2.length()==8){
                   System.out.println(str2);

        }
            
       }
  
       }
}


全部评论

相关推荐

2024-12-11 09:14
门头沟学院 软件测试
2025毕业等一个offer:女生终于扳回一局
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务