返回列表 發帖
  1. import java.untl.Scanner;
  2. public class Ch24 {

  3.         public static void main(String[] args) throw MyException

  4.         java.util.Scanner s=new Scanner(System.in);
  5.         {
  6.                 float x,y;
  7.                 System.out.print("輸入分子");
  8.                 x=s.nextFloat();
  9.                 System.out.print("輸入分母");
  10.                 y=s.nextFloat();
  11.                 if(y==0)
  12.                         throw new MyException("分母不可為零");
  13.                 System.out.println(x+"/"+y+'='+(x/y));

  14.         }

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

TOP

返回列表