- import java.util.*;
- public class z
- {
- public static void main(String args[])throws MyException
- {
- int x,y;
- Scanner s=new Scanner(System.in);
- System.out.print("分子:");
- x=s.nextInt();
- System.out.print("分母:");
- y=s.nextInt();
- if(y==0)
- {
- throw new MyException("分母不可為零!");
- }
- System.out.println("此數為:"+x/y);
- }
- }
- class MyException extends Exception
- {
- MyException(String str)
- {
- super(str);
- }
- }
複製代碼 |