- import java.util.Scanner;
- public class Ch20
- {
- static Scanner s=new Scanner(System.in);
- public static void main(String[] args) throws MyException
- {
- float a,b;
- System.out.print("輸入分子: ");
- a=s.nextFloat();
- System.out.print("輸入分母: ");
- b=s.nextFloat();
- if(b==0)
- throw new MyException("嘿嘿嘿~分母不可為零喔!");
- System.out.println(a+"/"+b+"="+a/b);
- }
- }
- class MyException extends Exception
- {
- MyException(String str)
- {
- super(str);
- }
- }
複製代碼 |