返回列表 發帖
  1. import java.util.Scanner;
  2. public class Ch28
  3. {
  4.   public static void main(String args[]) throws MyException
  5.   {
  6.     Scanner c=new Scanner(System.in);
  7.     float x,y;
  8.     System.out.print("請輸入x:");
  9.     x=c.nextFloat();
  10.     System.out.print("請輸入y:");
  11.     y=c.nextFloat();

  12.     if(y==0)
  13.     {
  14.       System.out.println("分母不可為0!!!");
  15.     }
  16.    
  17.     System.out.print("x/y="+(x/y));
  18.   }

  19.   class MyException extends Exception
  20.   {
  21.     MyException(String str)
  22.     {
  23.       super(str);
  24.     }
  25.   }
  26. }
複製代碼

TOP

返回列表