返回列表 發帖
  1. package a01;
  2. import java.util.*;
  3. public class a01 {
  4.         static Scanner s =new Scanner(System.in);

  5.         public static void main(String[] args) throws MyException{
  6.                 float x,y;
  7.                 System.out.print("輸入分子:");
  8.                 x = s.nextFloat();
  9.                 System.out.print("輸入分母:");
  10.                 y = s.nextFloat();
  11.                 if(y==0)
  12.                         throw new MyException("分母不可為0喔!");
  13.                         System.out.println(x+"/"+y+"="+(x/y));               
  14.                         }
  15.                     }
  16. class MyException extends Exception
  17. {
  18.         MyException(String str)
  19.         {
  20.                 super(str);
  21.         }
  22. }
複製代碼

TOP

返回列表