package cn.practice;
public class VarableParameter {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(add(2,3));
System.out.println(add(2,3,5));
}
public static int add(int x, int ... args){
int sum = 0;
for(int i = 0; i <= args.length; i++){
sum += args[i];
}
return sum;
}
}
//报错
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at cn.practice.VarableParameter.add(VarableParameter.java:19)
at cn.practice.VarableParameter.main(VarableParameter.java:10)
//自己第一次用Eclipse 对于调试和报错提示不太懂
|
|