获取ArrayOutOfBoundsException
public class Ex4 {
public static void main(String[] args) {
if(args.length < 1 | args.length > 3){System.out.println("number of
arguments invalid");}
else{
try{
double a = Double.parseDouble(args[0]);
double b = Double.parseDouble(args[1]);
double c = Double.parseDouble(args[2]);
if(args.length ==1){System.out.println(a);}
else if (args.length == 2){System.out.println(a*b);}
else if(args.length == 3){System.out.println(a*b*c);}
}
catch(NumberFormatException e){System.out.println("invalid operation");}
}
}
}
}
当我仅输入一个命令行参数(例如“ 3”)时,根据BlueJ,我在第10行收到ArrayOutofBounds异常。当输出应为3.0