1. 編寫一個類ExceptionTest,在main方法中使用try-catch-finally語句結構實現:


package bbb;

import java.util.Scanner;

public class aaa {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("請輸入除數:");
        int op1 = input.nextInt();
        System.out.println("請輸入被除數:");
        int op2 = input.nextInt();
        int result = 0;
        try {
            result = op1 / op2;
        } catch (ArithmeticException e) {
            e.printStackTrace();
        } finally {
            System.out.println("異常處理");
        }
        System.out.println(result);
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM