1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
public class Demo03 { public static void main(String[] args) { System.out.println(mySum(1)); System.out.println(mySum(1,2,3)); System.out.println(mySum(1,2,3,4)); System.out.println(mySum(1,2,3,4,5)); System.out.println(mySum(1,2,3,4,5,6)); System.out.println(mySum(1,2,3,4,5,6,7)); System.out.println(mySum(1,2,3,4,5,6,7,8)); System.out.println(mySum(1,2,3,4,5,6,7,8,9)); System.out.println(mySum(1,2,3,4,5,6,7,8,9,10));
}
private static int mySum(int b,int ... a) { int sum = 0; for (int n : a) { sum += n; } return sum; } }
|