返回列表 發帖
  1. import java.util.Scanner;
  2. public class ch46
  3. {
  4.     public static void main(String args[])
  5.     {
  6.       for(ont i=1;i<=3;i++)
  7.       {
  8.         try
  9.         {
  10.             int a, b;
  11.             Scanner s=new Scanner(System.in);
  12.             System.out.print("請輸入分子: ");
  13.             a=s.nextInt();
  14.             System.out.print("請輸入分母: ");
  15.             b=s.nextInt();
  16.             System.out.println(a+"/"+b+"="+(a/b));
  17.         }
  18.         catch(java.lang.ArtithmeticException e)
  19.         {
  20.             System.out.println("運算錯誤 分母不能為零");
  21.         }
  22.         catch(java.util.InputMismatchException e)
  23.         {
  24.             System.out.println("格式錯誤!請輸入整數");
  25.         }
  26.         if(i==3)
  27.             System.out.println("錯誤多次,跳出程式");
  28.       }
  29.     }
  30. }
複製代碼

TOP

返回列表