返回列表 發帖
  1. import java.util.*;
  2. public class Queen
  3. {
  4.         public static void main(String args[])throws MyException
  5.         {
  6.                   int a,b;
  7.       
  8.           Scanner s=new Scanner(System.in);
  9.           System.out.print("輸入分子:");
  10.           a=s.nextInt();
  11.           System.out.print("輸入分母:");
  12.           b=s.nextInt();
  13.           if(b==0)
  14.           {
  15.                   throw new MyException("嘿嘿嘿~分母不可為0喔~");
  16.           }
  17.           System.out.print(a+"/"+b+"="+(a/b));
  18.                                        
  19.         }
  20.        
  21. }
  22. class MyException extends Exception
  23. {
  24.         MyException (String str)
  25.         {
  26.                 super(str);
  27.         }
  28. }
複製代碼

TOP

返回列表