返回列表 發帖
  1. import java.util.Scanner;


  2. public class Ch03 {
  3.         static Scanner s = new Scanner(System.in);
  4.         public static void main(String[] args) throws MyException {
  5.                 float x,y;
  6.                 System.out.print("輸入分子: ");
  7.                 x=s.nextFloat();
  8.                 System.out.print("輸入分母: ");
  9.                 y=s.nextFloat();
  10.                 if(y==0)
  11.                 {
  12.                         throw new MyException("分母不能為零!");
  13.                 }
  14.                 System.out.println(x+"/"+y+"="+(x/y));
  15.         }

  16. }
  17. class MyException extends Exception
  18. {
  19.         MyException(String str)
  20.         {
  21.                 super(str);
  22.         }
  23. }
複製代碼

TOP

返回列表