题解 | #字符串分隔#

字符串分隔

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

public static void main(String[] args) throws IOException {
      Scanner sc = new Scanner(System.in);
        while (sc.hasNextLine()){
            String str = sc.nextLine();//输入字符串
//            调用切割方法
            split(str);
        }
    }
    public static void split(String str){
        while(str.length()>=8){
            System.out.println(str.substring(0,8));
            str=str.substring(8);
        }
        if(str.length()0){
            str+="00000000";
            System.out.println(str.substring(0,8));
        }
    }

此方法是copy别人的 只说一下我发现的一个小小的注意点
只能使用hasNaxt()方法 和 nextLine()方法 否则无法处理字符串中的空格

全部评论

相关推荐

notbeentak...:真的nc,算毕业6月份,要给这种b公司打半年多白工😅
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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