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

TOP

返回列表