返回列表 發帖
  1. package bbs.istak.org.tw;

  2. import java.util.Scanner;

  3. public class Main {

  4.         public static void main(String[] args) throws MyException {
  5.                 // TODO 自動產生的方法 Stub
  6.                 Scanner scanner=new Scanner(System.in);
  7.         System.out.print("請輸入分子");
  8.         int num1=scanner.nextInt();
  9.         System.out.print("請輸入分母");
  10.         int num2=scanner.nextInt();
  11.         int result=0;
  12.         if(num2!=0){
  13.             result=num1/num2;
  14.     }
  15.     else{
  16.             throw new MyException("分母不可以為零");
  17.     }
  18.         System.out.println(result);
  19.         }

  20. }
複製代碼
寶寶心裡苦,但寶寶不說。

TOP

返回列表