博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
课后作业
阅读量:6863 次
发布时间:2019-06-26

本文共 4126 字,大约阅读时间需要 13 分钟。

一.下列语句哪一个将引起编译错误?为什么?哪一个会引起运行时错误?为什么?

m=d; d=m; d=(Dog)m; d=c; c=(Cat)m;

d=m;和d=c;引起编译错误;

原因:

二.CatchWho.java

源代码:

public class CatchWho {     public static void main(String[] args) {         try {             try {                 throw new ArrayIndexOutOfBoundsException();             }             catch(ArrayIndexOutOfBoundsException e) {                System.out.println(  "ArrayIndexOutOfBoundsException" +  "/内层try-catch");             }             throw new ArithmeticException();         }         catch(ArithmeticException e) {             System.out.println("发生ArithmeticException");         }         catch(ArrayIndexOutOfBoundsException e) {            System.out.println(  "ArrayIndexOutOfBoundsException" + "/外层try-catch");         }     } }

三.CatchWho2.java

源代码:

public class CatchWho2 {     public static void main(String[] args) {         try {            try {                 throw new ArrayIndexOutOfBoundsException();             }             catch(ArithmeticException e) {                 System.out.println( "ArrayIndexOutOfBoundsException" + "/内层try-catch");             }            throw new ArithmeticException();         }         catch(ArithmeticException e) {             System.out.println("发生ArithmeticException");         }         catch(ArrayIndexOutOfBoundsException e) {             System.out.println( "ArrayIndexOutOfBoundsException" + "/外层try-catch");         }     } }

四.EmbededFinally.java

源代码:

public class EmbededFinally {        public static void main(String args[]) {                int result;                try {                        System.out.println("in Level 1");                        try {                                System.out.println("in Level 2");  // result=100/0;  //Level 2                                try {                                        System.out.println("in Level 3");                                           result=100/0;  //Level 3                                }                                 catch (Exception e) {                                        System.out.println("Level 3:" + e.getClass().toString());                                }                                                finally {                                        System.out.println("In Level 3 finally");                                }                                               // result=100/0;  //Level 2                            }                        catch (Exception e) {                                System.out.println("Level 2:" + e.getClass().toString());                        }             finally {                                System.out.println("In Level 2 finally");                        }                         // result = 100 / 0;  //level 1                }                 catch (Exception e) {                        System.out.println("Level 1:" + e.getClass().toString());                }                finally {           .             System.out.println("In Level 1 finally");                }        }}

五.课后作业

源代码:

package zuoye3;import java.util.Scanner;public class Fenshu {    public static void main(String[] args)    {        int s = 0,a=0;        System.out.println("请输入分数");        Scanner b=new Scanner(System.in);        try        {        s=Integer.parseInt(b.next());        if(s>90&&s<=100){        a=1;        }else if(s>80&&s<=90){        a=2;        }else if(s>70&&s<=80){        a=3;        }else if(s>60&&s<=70){        a=4;        }else if(s>=0&&s<=60){        a=5;        }        switch(a)        {        case 1:        {            System.out.println("优");        break;        }        case 2:        {            System.out.println("良");            break;        }        case 3:        {            System.out.println("中");            break;        }        case 4:        {            System.out.println("及格");            break;        }        case 5:        {            System.out.println("不及格");            break;        }        }            }            catch(Exception e){        System.out.println("错误");            }}    }

 

转载于:https://www.cnblogs.com/zyldbk/p/4966293.html

你可能感兴趣的文章
Centos7修改默认启动级别(命令行,图形切换)
查看>>
php 入门笔记
查看>>
INotifyPropertyChanged接口应用示例
查看>>
OC-copy
查看>>
epel源报错怎么解决?
查看>>
网页屏幕缩小到出现水平滚动条后,背景不能100%填充
查看>>
11-python-字符串、列表、元组、字典的作业
查看>>
动态链接库和静态链接库
查看>>
移动web开发适配方案之Rem
查看>>
vue2.0组件的生命周期
查看>>
文件上传并改名
查看>>
带通配符的字符串匹配问题
查看>>
关于学习uCOS-II
查看>>
Servlet 中利用阿里云包fastjson-1.2.43.jar把map转为Json并返回前端
查看>>
我们为何要付出高昂的代价去获取智力?
查看>>
搜索 --- 数独求解 POJ 2676 Sudoku
查看>>
调用DLL
查看>>
1115. Counting Nodes in a BST (30)
查看>>
UVA 814 The Letter Carrier's Rounds(JAVA基础map)
查看>>
BZOJ5343[Ctsc2018]混合果汁——主席树+二分答案
查看>>