public class Main { public static void main(String[] args) { //write your code here........ // 定义数组大小,因为 int类型 范围再 2^-31 ~ 2^31 - 1 // 而 9999999999 超过类 int类型的最大范围 long arr[] = new long[10]; // 数列:9,99,999,...,9999999999 的 // 通项公式为 an = 10^n - 1;但是再java中有专门的方法表示 // Math.pow(a,b); 表示 a 的 b 次方 for (int i = 0; i < 10; i++){ // 因为i 是从 0 开始,所以pow(10,i+1) long a = (long)Math.pow(10,i+1) - 1; arr[i] = a; } long count = 0; // 遍历数组求和 for (int i = 0; i < arr.length; i++){ count += arr[i]; } System.out.println(count); } }