题解 | #字符串分隔#

字符串分隔

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
            String s = in.nextLine();
            split(s);
            
        }
        
    }

    public static void split(String s){
        while(s.length()>=8){
            System.out.println(s.substring(0,8));
            s = s.substring(8);
        }
        if(s.length()<8 && s.length()>0){
            s += "00000000";
            System.out.println(s.substring(0,8));
        }
    }
}
  1. 我就是最蠢的人,为什么我想不出这样的解题思路,这就是人和人之间的区别吗
  2. 获取输入的字符串
  3. sub分割
  4. 判断分割之后的是否大于8
  5. while循环分割直到小于8
  6. 然后最后剩余不足8位的补0
  7. 解题完成,这就是大佬的智慧,我是废物
#笔试题解#
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务