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

TOP

返回列表