第七章

来源:互联网 发布:p2p网络管理 编辑:程序博客网 时间:2024/05/16 19:28

1.不对。

2.

public class yichang {public static void main(String[] args) {  System.out.print("Please input an Integer: ");   int value = new Scanner(System.in).nextInt();    try{   if(value < 0){    throw new MyException("My Exception comes!");    }   }catch (MyException myExp){   System.out.println("MyExcepton caugth!");   } }}class MyException extends Exception{  public MyException(String s){  System.out.println("MyException occurs. The value must be greater than ZERO!"); }}
3.当应用程序试图在需要对象的地方使用 null 时,抛出该异常。这种情况包括:调用 null 对象的实例方法。
访问或修改 null 对象的字段。
将 null 作为一个数组,获得其长度。
将 null 作为一个数组,访问或修改其时间片。
将 null 作为 Throwable 值抛出。

4.输出: exception000
              exception111
              finished
去黑体输出:exception111
                    exception
                    finished
去斜体输出:exception000
                    finished

5.输出结果:13423

6.

public static void main(String[] args) {        // 输入计算参数        Integer a = 2;        Integer b = 1;        try {            double cc = b/(double)a; //这样才能计算小数,不会报除0错误            System.out.println("cc:"+cc);        } catch (NullPointerException e) {            System.out.println("空指针异常");        }catch (ArithmeticException e) {            System.out.println("计算异常");        }catch (Exception e) {            System.out.println("其他异常");            e.printStackTrace();        }    }


7.

import java.util.Scanner;public class Input {     public static void main(String[] args) {           int index = 0;           int[] array = new int[10];           int max,min;           while (true) {                 if (index == array.length) { break;}                 Scanner sc = new Scanner(System.in);                 System.out.print("输入[" + (index + 1) + "]:");                 try {                      array[index] = sc.nextInt();                      index++;                  }                   catch (Exception e) {System.out.println("输入错误,重新输入!");}            }            max = array[0];            min = array[0];            for (int i = 1; i < array.length; i++) {                  if (array[i] > max) {max = array[i];}                  if (array[i] < min) {min = array[i];}             }            System.out.println("max = " + max);            System.out.println("min = " + min);      }}

8.throws TimeOutException

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 买的狗得病了怎么办 剖腹产9天刀口痒怎么办 剖腹产6天刀口痒怎么办 剖腹产2年刀口痒怎么办 破腹产9天刀口痒怎么办 破腹产7天刀口痒怎么办 剖腹产8天伤口痒怎么办 刨腹产9天刀口痒怎么办 破腹产8天刀口痒怎么办 二胎刀口1.1mm薄怎么办 土豪养成记2闪退怎么办 爱上不该爱的人怎么办? 有妇之夫爱上我,怎么办 全身起疙瘩很痒怎么办 怀孕了肚子很痛怎么办 月经来肚子疼的厉害怎么办 孕妇9个月肚子疼怎么办 斗鱼身上长白点怎么办 8个月宝宝肚子疼怎么办 1岁半宝宝肚子痛怎么办 3岁宝宝肚子疼怎么办啊 吃的太辣肚子疼怎么办 2岁半宝宝肚子疼怎么办 2岁宝宝肚子痛哭怎么办 怀孕3个月拉肚子怎么办 一岁宝宝消化不良拉肚子怎么办 后背长好多痘痘怎么办 身上起疹子很痒怎么办 背上长好多痘痘怎么办 月经两三个月不来怎么办 来月经很少是褐色的怎么办 例假一天就没了怎么办 月经来一天就没了怎么办 假体隆胸8年怀孕怎么办 1岁宝宝长湿疹怎么办 2017卓达破产后怎么办 8岁儿童反复发烧怎么办 工商年报报错了怎么办 买房契税票丢了怎么办 合同地址写错了怎么办 货物被海关扣了怎么办