题解 | #数列求和#

数列求和

https://www.nowcoder.com/practice/6893484c04c24bfca1f606b1823a468d

import java.util.StringJoiner;

public class Main {
    public static void main(String[] args) {

        //write your code here........
        StringJoiner joiner = new StringJoiner(",");
        String a = "";
        long total = 0L;
        for (long i = 1; i <= 10; i++) {
            a = "9" + a;
            joiner.add(a);
            //计算
            total = total + Long.valueOf(a);
        }
        //System.out.println(joiner.toString());
        System.out.println(total);

    }
}

全部评论

相关推荐

09-29 00:03
门头沟学院 Java
点赞 评论 收藏
分享
09-24 18:30
已编辑
长春工业大学 产品经理
小肥罗:HR就是好人的缩写哈哈哈哈
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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