已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
任课教师 宋瑾钰任课教师 宋瑾钰 JAVA 程序设计程序设计 2011 2012 学年第学年第 2 学期 学期 实实 验验 报报 告告 学号 学号 E10700217 姓名 廖远东姓名 廖远东 班级 数字媒体班级 数字媒体 2 班班 浙江理工大学信息学院 实验指导书 实验名称 包 接口与异常处理 学时安排 2 实验类别 综合设计型实验 实验要求 1 人 1 组 一 实验目的 1 掌握 java 字符串处理方法 2 掌握 java 面向对象的概念 3 掌握 java 自定义异常和处理 4 通过实验 对 Java 程序的开发有一个深入了解 二 实验内容 1 阅读并分析程序 TestException java 见附件 PPT 文件 2 习题 2 编程 见 P85 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 args TestException testException1 new TestException try testException1 testEx catch Exception e e printStackTrace 2 import java util Scanner import java util Input public class experience2 public static void main String args int year 0 try Scanner scan new Scanner System in year scan nextInt System out printf d n year catch Exception e System out println ERROR System out printf d n year 3 package friddle test import java util Scanner public class experience3 public static void main String args boolean run true while run double num1 num2 result num1 num2 result 0 String function new String try System out println please input the nmber1 Scanner scan new Scanner System in num1 scan nextDouble System out println please input the nmber2 scan new Scanner System in num2 scan nextDouble catch Exception e System out println the put number is wrong try System out println please input you function Scanner scan new Scanner System in function scan next catch Exception e System out println the put number is wrong if function equals result num1 num2 if function equals result num1 num2 if function equals result num1 num2 if function equals result num1 num2 System out printf f n result System out println continue Y N Scanner right new S
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年金属非切削、成形加工机械项目建议书
- 2025年鼻毛修剪器项目建议书
- 2025年聚羧酸系减水剂合作协议书
- Edoxaban-impurity-8-生命科学试剂-MCE
- Dabigatran-impurity-37-生命科学试剂-MCE
- 建筑物外立面装饰施工方案
- Canagliflozin-impurity-79-生命科学试剂-MCE
- 2025年书法硬笔考试题库及答案
- 2026年中国笔记本电脑电源适配器项目经营分析报告
- 2025年铜川书法联考真题及答案
- 2025新疆中新建数字发展有限责任公司招聘31人笔试考试参考题库及答案解析
- 流程改造三年计划
- 初二语文2025年上学期期中专项训练复习试卷(含答案)
- 关键时刻MOT完整讲义
- 业主大会业主委员会备案表
- 《少年中国说》集体配乐朗诵表演创意设计
- 腹腔镜肾上腺切除术的临床应用
- TSDDA 0002-2021 住宅装饰装修工程质量验收标准
- 金字塔写作原理PPT
- DB33-T1177-2019《城镇净水厂安全运行管理规范》
- 思想道德与法治课件:第六章 第四节 自觉尊法学法守法用法
评论
0/150
提交评论