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

TOP

返回列表