题解 | #数列求和#
数列求和
http://www.nowcoder.com/practice/6893484c04c24bfca1f606b1823a468d
public class Main {
public static void main(String[] args) {
long[] a = new long[10];
long sum =0;
//write your code here........
for(int i = 0; i<10;i++){
if(i==0) {
a[0]=9;
}else{
a[i]=a[i-1]+9*(long)(Math.pow(10,i));
}
sum = sum+a[i];
}
System.out.print(sum);
}
}
public static void main(String[] args) {
long[] a = new long[10];
long sum =0;
//write your code here........
for(int i = 0; i<10;i++){
if(i==0) {
a[0]=9;
}else{
a[i]=a[i-1]+9*(long)(Math.pow(10,i));
}
sum = sum+a[i];
}
System.out.print(sum);
}
}