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