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

TOP

返回列表