本帖最后由 风云 于 2013-6-12 17:01 编辑
package cn.itcast.day1;
public class VarableParameter {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(bb(2,3));
System.out.println(bb(2,3,5));
}
public static int bb(int x,int... args){
int sum = x;
for(int i=0;i<=args.length;i++){
sum += args;
}
return sum;
}
}
运行这个小程序时为什么会提示这样的错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at cn.itcast.day1.VarableParameter.bb(VarableParameter.java:15)
at cn.itcast.day1.VarableParameter.main(VarableParameter.java:9) |