题解 | #数列求和#

数列求和

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

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

        //write your code here........
        long[] arrys = new long[10];//定义一个长度为10的long数组
        arrys[0] = 9;//数组的第一个数为9
        long num = 0;//定义一个循环次数
        for(int i =1;i <10;i++){
            arrys[i] = arrys[i-1]*10+9;
            num += arrys[i];//num+=arrys循环的次数
        }
        System.out.println(num+9);
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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