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

  2. public  class  Ch01{
  3.         static Scanner s=new Scanner(System.in);
  4.         publc static void main(String[] args) throws Exception{
  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.                         throw new Exception("分母不可為零");
  12.                 System.out.println(x+"/"+y+"="+(x/y));
  13.              }
  14.         }
  15. class MyException extends Exception
  16. {
  17.           MyException(String str) {
  18.                   super(str);
  19.                
  20.         }
  21. }
複製代碼

TOP

返回列表