java实验二报告格式.doc_第1页
java实验二报告格式.doc_第2页
java实验二报告格式.doc_第3页
java实验二报告格式.doc_第4页
java实验二报告格式.doc_第5页
已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论