本帖最後由 林羿丞 於 2021-1-16 11:23 編輯
- package aaa;
- import java.util.*;
- public class aaa
- {
- public static void main(String[] args) throws MyException
- {
-
-
-
-
- Scanner s=new Scanner(System.in);
- int x,y;
- System.out.print("輸入分子: ");
- x=s.nextInt();
- System.out.print("輸入分母: ");
- y=s.nextInt();
- if(y==0)
- throw new MyException("嘿嘿嘿~分母不可為零喔!");
- System.out.println(x+"/"+y+"="+(x/y));
- }
- }
- class MyException extends Exception
- {
- MyException(String str)
- {
- super(str); //呼叫父類別的建構子
- }
- }
複製代碼 |