- package kao;
- import java.util.Scanner;
- public class Main
- {
- public static void main(String[] args) throws MyException
- {
- Scanner scanner=new Scanner(System.in);
- System.out.print("請輸入分子:");
- int num1=scanner.nextInt();
- System.out.print("請輸入分母:");
- int num2=scanner.nextInt();
- int result=0;
- if(num2 !=0)
- result=num1/num2;
- else
- throw new MyException("分母不可為0");
- System.out.println(result);
- }
- }
複製代碼 |