返回列表 發帖
  1. import java.util.InputMismatchException;
  2. import java.util.Scanner;
  3. public class Ed
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.             int n=0;
  8.                 while(true)
  9.             {
  10.                         if(n==3)a
  11.                         {
  12.                                 System.out.println("錯誤嘗試過多,程式跳出!");
  13.                                 return;
  14.                         }
  15.                     try
  16.                     {
  17.                            
  18.                             Scanner s=new Scanner(System.in);
  19.                         int x,y;
  20.                         System.out.print("輸入分子: ");
  21.                         x=s.nextInt();
  22.                         System.out.print("輸入分母: ");
  23.                         y=s.nextInt();
  24.                         System.out.println(x+"/"+y+"="+(x/y));
  25.                     }catch(ArithmeticException e)
  26.                     {
  27.                             System.out.println("運算錯誤!分母不可為0");
  28.                             n++;
  29.                     }catch(InputMismatchException e)
  30.                     {
  31.                         System.out.println("程式錯誤!請輸入整數!");
  32.                         n++;
  33.                 }
  34.             }
  35.         }

  36. }
複製代碼

TOP

返回列表