- import java.util.*;
- public class ch52
- {
- public static void main(String[] args)
- {
-
- int x,y;
- for(int i=1;i<=3;i++)
- {
- try
- {
- Scanner s=new Scanner(System.in);
- System.out.print("輸入分子: ");
- x=s.nextInt();
- System.out.print("輸入分母:");
- y=s.nextInt();
- System.out.print(x+"/"+y+"="+(x/y));
- return;
- }
- catch(InputMismatchException e)
- {
- System.out.println("格式錯誤!");
- }
- catch(ArithmeticException e)
- {
- System.out.println("運算錯誤!");
- }
- if(i==3)
- System.out.println("錯誤過多!程式跳出");
- }
- }
- }
複製代碼 |