- package main2 ;
- import java.util.Scanner;
- public class Main2 {
- public static void main(String[] args) throws MyException {
- // TODO 自動產生的方法 Stub
- 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("分母不可以為零");
- }
- System.out.println(result);
- }
- }
複製代碼 |