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