- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
《Java语言与面向对象程序设计基础》课程
实验报告姓名:学号:
实验题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!!!);
}
}
}
运行结果
[实验程序运行结果]
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!!!);
}
}
}
}
运行结果
[实验程序运行结果]
public class ArithmeticExceptionTest{
public static void main(String arg[]){
int s=100;
for (int i=-3;i5;i++){s=s/i;}
public class ArithmeticExceptionTest{
public static void main(String arg[]){
int s=100;
for (int i=-3;i5;i++){
try{
s=s/i;
}catch(ArithmeticException e){
System.out.println(e);
}
System.out.println(s);
}
}
}
运行结果
[实验程序运行结果]
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(Its OK!);
}
}
运行结果
[实验结论与收获]
实验题2
[实验要求]
在选择“兴趣爱好”的窗体中,有旅游、运动、阅读等选项,编写小程序,完成兴趣爱好的选择,并输出到文本框中。
记录调试过程、步骤、程序和运行结果。
[实验程序]
import java.awt.*;
import java.awt.event.*;
class Test2 extends WindowAdapter implements ItemListener
{ Fr
您可能关注的文档
最近下载
- 塔望食品品牌策划:品牌就是生意,功能饮料行业如何正确品牌定位.pdf VIP
- 2023春国开电大《行政法与行政诉讼法》形考任务(形成性考核作业1)试题及答案.pdf VIP
- HGT20592_20635-2009钢制管法兰、垫片和紧固件(法兰选取).pdf VIP
- 中国脱硫脱硝除尘项目商业计划书.docx VIP
- 国家电网有限公司营销现场作业安全工作规程(试行).docx VIP
- 全科医生转岗培训考试(理论考核)题库及答案(2025年深圳).docx VIP
- 手工贴标工艺培训.pptx
- 电梯(困人)机房救援说明.doc VIP
- Power BI数据分析与可视化案例教程.pptx
- 建设法规测验.doc VIP
文档评论(0)