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

TOP

返回列表