一个简单的Java程序,为什么不通? 请高手指教.
程序如下所示(程序结尾附有错误信息):
public class BreakContinue {
public static void main(String[] args){
int n = Integer.parseInt(args[0]);
switch(n){
case 1:
System.out .println("n="+n+" ") ;
case 2:
System.out.println("n*n="+n*n+" ") ;
case 3:
System.out.println("n*n*n="+n*n*n+" ") ;
break;
case 4:
int sum = 0;
for (int i=0;i<=n*n;i++){
if((i%2)==1)
continue;
sum += i;
System.out.println(i+"+");
}
System.out.println ("="+sum);
break;
default:
int i ;
for(i=3;i>=1;i--) {
first: {
second:{
third:{
System.out.println("i="+i) ;
if(i==1)
break first;
if(i==2)
break second;
if(i==3)
break third;
}
System.out.println("third");
}
System.out.println("second");
}
System.out.println("first");
}
}
}
}
错误如下:java.lang.ArrayIndexOutOfBoundsException: 0
at studyfromzero.BreakContinue.main(BreakContinue.java:5)
Exception in thread "main"