题解 | 动态字符串

动态字符串

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

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();

        //write your code here......
        int startIndex = str.length() % 3;
        System.out.print(str.substring(0, startIndex));
        for(int i = startIndex; i < str.length(); ){
            if(i + 3 > str.length()){
                System.out.print("," + str.substring(i));
                break;
            }
            System.out.print("," + str.substring(i, i + 3));
            i += 3;
        }
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
09-25 16:03
点赞 评论 收藏
分享
写不来代码的小黑:这好像是boss默认的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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