返回列表 發帖
  1.     import java.util.Scanner;
  2.     public class Ch51
  3.     {
  4.         static Scanner s=new Scanner(System.in)
  5.         public static void main(String[] args) throws MyException
  6.         {   
  7.             float x,y;
  8.             System.out.print("輸入分子: ");
  9.             x=s.nextFloat();
  10.             System.out.print("輸入分母: ");
  11.             y=s.nextFloat();
  12.             if(y==0)
  13.                 throw new MyException("No Zero For denominator!");
  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

  1. import java.util.Scanner;
  2. public class Ch5
  3. {
  4.     static Scanner s=new Scanner(System.in);

  5.     public static void main(String[] args) throws MyException
  6.     {   
  7.         float x,y;
  8.         System.out.print("輸入分子: ");
  9.         x=s.nextFloat();
  10.         System.out.print("輸入分母: ");
  11.         y=s.nextFloat();
  12.         if(y==0)
  13.             throw new MyException("嘿嘿嘿~分母不可為零喔!");
  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

返回列表