java实验2验报告.docVIP

  • 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

文档评论(0)

1亿VIP精品文档

相关文档