- 7
- 0
- 约3.63万字
- 约 10页
- 2016-12-03 发布于河南
- 举报
java实验2验报告
实验指导书
实验名称:包、接口与异常处理 学时安排:2
实验类别:综合设计型实验 实验要求:1人1组
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
一、实验目的
1、掌握java字符串处理方法。
2、掌握java面向对象的概念。
3、掌握java自定义异常和处理。
4、 通过实验,对Java程序的开发有一个深入了解。
二、实验内容
1.阅读并分析程序TestException.java。(见附件PPT文件)
2.设计一个程序,其功能是从命令行输入整数字符串,再将该整数字符串转换为整数,输入的数据可能具有以下格式:12345、123 45、123xyz456
3.编写一个四则运算程序,要求用户输入一个x值和一个y值,以及一个四则运算符。如果用户输入正确,则给出运算结果,如果输入错误,则给出出错警告。(利用异常处理编程,尽量使用java现成的异常类,如没有可自定义异常类 )
三、程序代码
1.
public class TestException {
public TestException() {
}
boolean testEx() throws Exception{
boolean ret = true;
try{
ret = testEx1();
}catch (Exception e){
System.out.println(testEx, catch exception);
ret = false;
throw e;
}
finally{
System.out.println(testEx, finally; return value=+ret);
return ret;
}
}
boolean testEx1() throws Exception{
boolean ret = true;
try{
ret = testEx2();
if (!ret){
return false;
}
System.out.println(testEx1, at the end of try);
return ret;
}catch (Exception e){
System.out.println(testEx1, catch exception);
ret = false;
throw e;
}
finally{
System.out.println(testEx1, finally; return value=+ret);
return ret;
}
}
boolean testEx2() throws Exception{
boolean ret = true;
try{
int b=12;
int c;
for (int i=2;i=-2;i--){
c=b/i;
System.out.println(i=+i);
}
return true;
}catch (Exception e){
System.out.println(testEx2, catch exception);
ret = false;
throw e;
}
finally{
System.out.println(testEx2, finally; return value=+ret);
return ret;
}
}
public static void main(String[] a
您可能关注的文档
最近下载
- 求职简历模板免费下载-简历模板免费下载-word.docx VIP
- 2024年医院行风建设总结.pdf VIP
- FR 6011 说明书.pdf VIP
- 2025年中考物理总复习:压强(讲义)解析版.pdf VIP
- 酸碱盐-初升高化学知识复习讲义(人教版).pdf VIP
- 农业开发生态养鸡项目实施方案(有全套附表附图).doc VIP
- 劳动合同范本(2026年通用版,带试用期条款).docx VIP
- 医疗器械软件注册审查指导原则(2022年修订版)20220309.pdf VIP
- 老电影收藏1(1949—1966).doc VIP
- 西南18J517_厨房_卫生间_浴室设施_标准图集.pdf VIP
原创力文档

文档评论(0)