package zhang;
import java.util.Scanner;
public class keke {
void inputException(){
int a[]=new int[3]; //定义含有3个整型元素的数组a
Scanner sc=new Scanner(System.in);//创建一个输入的对象
System.out.println("输入三个整型数据:");//显示要输入的是3个整型的数据
int i;
for(i=0;i<3;i++)// //循环输入3个整型数据
a[i]=sc.nextInt();//输入整型数据
System.out.print("a["+i+"]="+a[i]);
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
keke test=new keke();//创建属于类 ExceptionTest的对象test
try
{//为方法inputException()进行监视
test.inputException();
}
catch(ArrayIndexOutOfBoundsException e){//捕获异常,并输入错误提示
System.out.println("数组越界"+e);
}
finally{//最终处理,输出相应的信息提示
System.out.println("最后一定被执行的语句");
}
}
}
对输入数据的异常处理
最新推荐文章于 2022-05-18 00:00:43 发布