收藏 分销(赏)

电大Java语言实验报告三.doc

上传人:綻放 文档编号:8915910 上传时间:2025-03-07 格式:DOC 页数:3 大小:899.37KB 下载积分:8 金币
下载 相关 举报
电大Java语言实验报告三.doc_第1页
第1页 / 共3页
电大Java语言实验报告三.doc_第2页
第2页 / 共3页


点击查看更多>>
资源描述
《Java 语言与面向对象程序设计基础》课程 实验报告三 姓名:xxx 学号:xxxxxxxxxxxxxx 实验题 1 [实验要求] 为本实验中程序添加异常处理机制 记录修改后程序和运行结果[实验程序] 程序 1-1 class A{} class B extends A{} public class ClassCastExceptionTest{ public static void main(String args[]){ A a=new A(); B b=(B)a; public class ClassCastExceptionTest{ public static void main(String args[]){ A a=new A(); try{ B b=(B)a; }catch(ClassCastException e){ System.out.println("catch ClassCastException!!!"); } } } 程序 1-2 public class ArrayIndexOutOfBoundsExceptionTest{ public static void main(String arg[]){ int a[]=new int [10]; for (int i=0 ;i<=10;i++){a[i]=0;} public class ArrayIndexOutOfBoundsExceptionTest{ public static void main(String arg[]){ int a[]=new int [10]; for (int i=0 ;i<=10;i++){ try{ a[i]=0; }catch(ArrayIndexOutOfBoundsException e){ System.out.println("catch ArrayIndexOutOfBoundsException!!!"); } } } } 程序 1-3 public class ArithmeticExceptionTest{ public static void main(String arg[]){ int s=100; for (int i=-3;i<5;i++){s=s/i;} public class ArithmeticExceptionTest{ public static void main(String arg[]){ int s=100; for (int i=-3;i<5;i++){ try{ s=s/i; }catch(ArithmeticException e){ System.out.println(e); } System.out.println(s); } } } 程序 1-4 public class StringException{ public static void main(String args[]){ String s1=new String("aaaa bbbb cccc"); System.out.println(s1); String s2; s2=s1.substring(30); System.out.println(s2); } } public class StringException{ public static void main(String args[]){ String s1=new String("aaaa bbbb cccc"); System.out.println(s1); String s2; try{ s2=s1.substring(30); System.out.println(s2); }catch(StringIndexOutOfBoundsException e){ System.out.println(e); } System.out.println("It's OK!"); } } [运行结果] 程序 1-1 程序 1-2
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 远程教育/电大

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服