题解 | #添加逗号#

添加逗号

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int tmp=n;
        int  count=0;
        while(tmp>0){
            count++;
            tmp/=10;
        }
        tmp=count/3;
        char[] arr=new char[count+tmp];
        tmp=0;
        for(int i=0;i<arr.length;i++){
            tmp++;
            arr[i]=(char)(n%10+'0');
            if(tmp%3==0&&tmp!=count){
                arr[i+1]=',';
                i++;
            }
            n=n/10;
        }
        tmp=arr.length-1;
        if(count%3==0)
            tmp--;
        for(int i=tmp;i>=0;i--){
            System.out.print(arr[i]);
        }
    }
}

全部评论

相关推荐

码农索隆:以下是我以我微薄的认知提供的建议: 1.考个教师资格证,去当体育考试。 2.去健身房当健身教练(因为在我印象里面体育生身材都不错)。
点赞 评论 收藏
分享
2025-12-18 19:36
已编辑
门头沟学院 Java
程序员牛肉:可以的,简历没毛病了。 虽然还是偏向同质化,不过学历不错。后续我觉得重心放到刷实习+摆脱同质化问题上
实习简历求拷打
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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