返回列表 發帖
  1. import java.util.Scanner;
  2. public class Ch50{
  3.        public static void main(String args[]) throws MyException{
  4.               int x,y;
  5.               Scanner s=new Scanner(System.in);
  6.               System.out.print("請輸入分子");
  7.               x=s.nextInt();
  8.               System.out.print("請輸入分母");
  9.               y=s.nextInt();
  10.               if(y==0)
  11.                       throw new MyException("分母禁止為0");
  12.               System.out.println("答案為: "+(x/y));

  13.        }
  14. }
  15. class MyException extends Exception{
  16.       MyException(String str){
  17.                        super(str);
  18.       }
  19. }
複製代碼
ABCDEFGHIJKLMNOPQRSTUVWXYZ

TOP

返回列表