返回列表 發帖
  1. import java.util.Scanner;
  2. public class Ch01
  3. {
  4.   public static void main(String[] args)
  5.     {
  6.         for(;;)
  7.         {
  8.             try
  9.             {
  10.               Scanner s=new Scanner(System.in);
  11.               int x,y;
  12.               System.out.print("輸入分子: ");
  13.                 x=s.nextInt();
  14.               System.out.print("輸入分母: ");
  15.                 y=s.nextInt();
  16.                System.out.println(x+"/"+y+"="+(x/y));
  17.             }catch(Exception e)
  18.              {
  19.                 System.out.println("程式發生錯誤!");
  20.                 System.out.println("例外類別: "+e.toString());
  21.             }
  22.             System.out.println();
  23.          }

  24.      }
  25. }
  26.                
  27.                
  28.                
  29.                
複製代碼

TOP

返回列表