java新手!为什么数不出来数组越界

a18703673235 2012-05-22 11:47:46
import java.io.*;
import java.util.*;
public class TestException1{
private int x;
private int y;
private int z;
private char a;
public int testException() throws

ArrayIndexOutOfBoundsException,IOException{
Scanner read=new Scanner(System.in);
x=read.nextInt();
y=read.nextInt();
char a = (char)new BufferedReader(new InputStreamReader

(System.in)).read();
try{

if(a=='T'||a=='t')
{ int iArray[]=new int[4]; iArray[10]=3;}
}catch(ArrayIndexOutOfBoundsException e){throw e;}
try{
z=x/y;
}catch(Exception e){
System.out.println(e.getMessage());
}
return z;
}


public static void main(String[] args){
try{
TestOfException test=new TestOfException();
test.testException();

}catch(ArrayIndexOutOfBoundsException e){
System.out.println("在main中捕获异常"+e);
}catch(IOException e){};
int result=test.testException();
System.out.println(result);

}
}
...全文
107 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
五哥 2012-05-23
  • 打赏
  • 举报
回复
把异常信息放出来嘛
a18703673235 2012-05-23
  • 打赏
  • 举报
回复
谢谢了,我找到原因了
JPF1024 2012-05-23
  • 打赏
  • 举报
回复
学习学习。。

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧