課後作業

來源:互聯網
上載者:User

標籤:

一.下列語句哪一個將引起編譯錯誤?為什麼?哪一個會引起執行階段錯誤?為什麼?

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("錯誤");            }}    }

 

課後作業

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.