云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > Java实验指导书44-49

Java实验指导书44-49

  • 62 次阅读
  • 3 次下载
  • 2025/12/12 3:55:09

作 业

一、作业内容(包括作业题目和解答)

1、 该程序能处理多种异常。

publicclassManyException { } }

System.out.println(\继续!!\); }

}

publicstaticvoid main(String[] args) {

inti;

inta[]={1,2,3,4}; for(i=0;i<5;i++){

try { }

catch(ArrayIndexOutOfBoundsExceptione) {

System.out .print(\捕获到了数组下标越界异常\);

System.out.println(\+i+\+i+\+(a[i]/i));

} {

catch(ArithmeticExceptione)

System.out .print(\异常类名称是:\+e);

} {

catch(Exception e)

System.out .println(\捕获\+e.getMessage()+\异常!\); }

finally{

System.out.println(\+i);

2、 编写一个Java程序,这个程序定义了一个能抛出异常的方法,在main()方法中捕获并处理该异常。

3、 编写一个Java程序,这个程序有两个异常类,在main()方法中使用throw语句抛出异常。

classAaaExceptionextends Exception{} classBbbExceptionextends Exception{}

classThrowException { { { } }

System.out.println(\执行bbb异常处理程序\); }

System.out.println(\执行aaa异常处理程序\); }

publicstaticvoid main(String[] args) {

intx=1; try{

thrownewAaaException();

if(x>0) else

thrownewBbbException(); }

catch (AaaExceptione)

catch (BbbExceptione)

4、编写一个Java程序,在main()方法中通过键盘读入一个字符。

importjava.io.*;

publicclassCatchException { }

publicstaticvoid main(String[] args) {

System.out.println(\程序开始\); try { }

catch(Exception e){}

System.in.read();

System.out.println(\程序结束\); }

搜索更多关于: Java实验指导书44-49 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

作 业 一、作业内容(包括作业题目和解答) 1、 该程序能处理多种异常。 publicclassManyException { } } System.out.println(\继续!!\); } } publicstaticvoid main(String[] args) { inti; inta[]={1,2,3,4}; for(i=0;i<5;i++){ try { } catch(ArrayIndexOutOfBoundsExceptione) { System.out .print(\捕获到了数组下标越界异常\);

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com