返回列表 發帖
  1. package kao;

  2. import java.util.Scanner;

  3. public class Main
  4. {
  5.         public static void main(String[] args) throws MyException
  6.         {
  7.                 Scanner scanner=new Scanner(System.in);
  8.         System.out.print("請輸入分子:");
  9.         int num1=scanner.nextInt();
  10.         System.out.print("請輸入分母:");
  11.         int num2=scanner.nextInt();
  12.         int result=0;
  13.         if(num2 !=0)
  14.                 result=num1/num2;
  15.         else
  16.                 throw new MyException("分母不可為0");
  17.         System.out.println(result);
  18.         }
  19. }
複製代碼

TOP

返回列表