隨堂小筆記

package edu.xcdq;

/**
 * @author yuhuicun
 * @date 2021/4/27 14:49
 */
public class Demo01 {

    public static void main(String[] args) {
        int divisor = 10;
        int dividend = 0;
        //System.out.println(divisor/dividend);//ArithmeticException   算數(shù)異常
        try{
            System.out.println(divisor/dividend);//ArithmeticException   算數(shù)異常
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("捕獲一個(gè)異常");
        }
        System.out.println("哈哈哈哈");
    }
}

Demo01

package edu.xcdq;

import java.util.Scanner;

/**
 * @author yuhuicun
 * @date 2021/4/27 15:07
 */
public class Demo02 {
    public static void main(String[] args) {

        int [] a = new int[2];
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        int j = scanner.nextInt();
        try{
            a[0] = i;
            a[2] = j;
            System.out.println(a[0]/a[2]);
        }catch (IndexOutOfBoundsException e){
            System.out.println("數(shù)組越界異常");
        }catch (NumberFormatException e) {
            System.out.println("數(shù)據(jù)格式不正確異常");
        }catch (ArithmeticException e ){
            System.out.println("算數(shù)異常");
        }
    }
}

Demo02

package edu.xcdq;

import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * @author yuhuicun
 * @date 2021/4/27 15:15
 */
public class Demo03 {
    public static void main(String[] args) {

        int[] a = new int[2];
        Scanner scanner = new Scanner(System.in);
        try {
            int i = scanner.nextInt();
            int j = scanner.nextInt();
            a[0] = i;
            a[2] = j;
            System.out.println(a[0] / a[2]);
        } catch (ArrayIndexOutOfBoundsException | InputMismatchException | ArithmeticException e) {
            System.out.println("數(shù)組越界異常");
            System.out.println("數(shù)據(jù)格式不正確異常");
            System.out.println("算數(shù)異常");
            System.out.println("以上異常中的一個(gè)");
        }
    }
}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 我做了自己最大的抗?fàn)?,我在無數(shù)次放棄自己的邊緣拯救自己。也許在別人的世界里我什么都不是,但在我的世界里,我是自己的英雄。
    橘子果醬orangeless閱讀 409評(píng)論 1 4
  • 學(xué)習(xí)webpack,直接觀看代碼理解。將自己的理解過程記錄下來,后續(xù)若有不同理解,再來修改。 獻(xiàn)上阮一峰老師的we...
    陳大沖閱讀 222,111評(píng)論 18 76
  • package edu.xcdq; public class Main { } 二 package edu.xcd...
    lwz001閱讀 289評(píng)論 0 0
  • 對(duì)應(yīng)視頻地址: (上集):https://www.bilibili.com/video/BV1BT4y1G73q[...
    VioletTec閱讀 401評(píng)論 0 2
  • Java多線程筆記 什么是線程? 線程是程序執(zhí)行的一條路徑,一個(gè)進(jìn)程中可以包含多條線程。一個(gè)應(yīng)用程序可以理解為一個(gè)...
    ZGYSYY閱讀 424評(píng)論 0 4

友情鏈接更多精彩內(nèi)容