返回列表 發帖
本帖最後由 湯郡一 於 2019-11-23 14:47 編輯
  1.         import java.util.Scanner;
  2.         public class Class2311
  3.         {
  4.             static Scanner s=new Scanner(System.in);
  5.           
  6.             public static void main(String[] args) throws MyException
  7.             {   
  8.                 float x,y;
  9.                 System.out.print("輸入分子: ");
  10.                 x=s.nextFloat();
  11.                 System.out.print("輸入分母: ");
  12.                 y=s.nextFloat();
  13.                 if(y==0)
  14.                     throw new MyException("嘿嘿嘿~分母不可為零喔!");
  15.                 System.out.println(x+"/"+y+"="+(x/y));
  16.             }
  17.         }
  18.         class MyException extends Exception
  19.         {
  20.             MyException(String str)
  21.             {
  22.                 super(str);   
  23.             }
  24.         }
複製代碼

TOP

返回列表