为什么我要获得,“线程中的例外”主要是“ java.lang.ArrayIndexOutOfBoundsException:0表示Lab164.main(magic.java:3)" [英] Why I am Getting,"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Lab164.main(magic.java:3)"
本文介绍了为什么我要获得,“线程中的例外”主要是“ java.lang.ArrayIndexOutOfBoundsException:0表示Lab164.main(magic.java:3)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class Test16 {
public static void main( String as []){
int a = Integer.parseInt(as [ 0 ]);
int b = Integer.parseInt(as [ 1 ]);
int c = Integer.parseInt(as [ 2 ]);
if (a> b){
if (a> c)
System.out.println(a + Is Maximum);
else
System.out.println(c + Is Maximum);
} 其他 {
如果(b> c)
系统.out.println(b + Is Maximum);
System.out.println(c + Is Maximum);
}
}
}
/ *
线程mainjava.lang中的异常。 ArrayIndexOutOfBoundsException:0
在Lab164.main(magic.java:3)
* /
解决方案
因为数组的实际大小为
小于预期。比如说,为了解决为[2]
,你必须至少有3个元素。
-SA
class Test16{
public static void main(String as []){
int a=Integer.parseInt (as[0]);
int b=Integer.parseInt (as[1]);
int c=Integer.parseInt (as[2]);
if(a>b){
if(a>c)
System.out.println(a+"Is Maximum");
else
System.out.println(c+"Is Maximum");
}else{
if(b>c)
System.out.println(b+"Is Maximum");
System.out.println(c+"Is Maximum");
}
}
}
/*
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Lab164.main(magic.java:3)
*/
解决方案
Because the actual size of the arrayas
is less then you expected. Say, to addressas[2]
, you have to have at least 3 elements.
—SA
这篇关于为什么我要获得,“线程中的例外”主要是“ java.lang.ArrayIndexOutOfBoundsException:0表示Lab164.main(magic.java:3)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文