import java.io.*;
public class testExceptionProc
{
int x=5,y,result;
int a[]={1,2};
public void process(int i){
if(i==1) System.out.println("输入1时无异常");
if(i==2) result=x/y;
if(i==3) a[9]=26;
}
public static void main(String[] args)
{
try{
process(1);
process(2);
process(3);
}
catch(ArithmeticException e){
System.out.println("算术异常已做了处理");}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("数组下标越界异常已作处理");}
catch(Exception e){
System.out.println(e.toString());
return;}
}
}
public class testExceptionProc
{
int x=5,y,result;
int a[]={1,2};
public void process(int i){
if(i==1) System.out.println("输入1时无异常");
if(i==2) result=x/y;
if(i==3) a[9]=26;
}
public static void main(String[] args)
{
try{
process(1);
process(2);
process(3);
}
catch(ArithmeticException e){
System.out.println("算术异常已做了处理");}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("数组下标越界异常已作处理");}
catch(Exception e){
System.out.println(e.toString());
return;}
}
}
解决方案 »
- Think in Java内的一习题的思考
- 自定义标签类--如何调用DAO
- 新手提问 请教高手
- 我写的计算器毛病在哪里 请高手们帮我详细指点一下 非常感谢!!
- 使用JMenuBar类、JMenu类和JMenuItem类创建的菜单可不可以添加快捷键?
- jbuilderx 编译错误:(Internal compiler error: java.lang.NullPointerException.)
- 谁有javadoc详细的使用方法?
- 客户用浏览器,怎么样在服务器得到客户的IP?急,在线等,谢谢
- 求助??关于TextField输入问题
- 上哪去download《Java 2 高级开发指南》的源码?
- java数据结构转化
- 数组小问题.
public class TestExceptionProc
{
int x=5,y,result;
int a[]={1,2};
public void process(int i){
if(i==1) System.out.println("输入1时无异常");
if(i==2) result=x/y;
if(i==3) a[9]=26;
}
public static void main(String[] args)
{
TestExceptionProc tep=new TestExceptionProc();
try{
tep.process(1);
tep.process(2);
tep.process(3);
}
catch(ArithmeticException e){
System.out.println("算术异常已做了处理");}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("数组下标越界异常已作处理");}
catch(Exception e){
System.out.println(e.toString());
return;}
}
}
public class testExceptionProc
{
int x=5,y,result;
int a[]={1,2};
public static void process(int i){
if(i==1) System.out.println("输入1时无异常");
if(i==2) result=x/y;
if(i==3) a[9]=26;
}
public static void main(String[] args)
{ try{
process(1);
process(2);
process(3);
}
catch(ArithmeticException e){
System.out.println("算术异常已做了处理");}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("数组下标越界异常已作处理");}
catch(Exception e){
System.out.println(e.toString());
return;}
}
}
import java.io.*;
public class testExceptionProc
{
static int x=5,y,result;
static int a[]={1,2};
public static void process(int i){
if(i==1) System.out.println("输入1时无异常");
if(i==2) result=x/y;
if(i==3) a[9]=26;
}
public static void main(String[] args)
{
for(int i=1;i<=3;i++){
try{
process(i);
}
catch(ArithmeticException e){
System.out.println("算术异常已做了处理");}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("数组下标越界异常已作处理");}
catch(Exception e){
System.out.println(e.toString());
return;}
}
}
}
改成static也可以执行,但是这就没有用到任何面向对象的思想了,给你的代码不参考……既然问题解决了,就结贴给分吧