- import java.util.Scanner;
- public class ch46
- {
- public static void main(String args[])
- {
- for(ont i=1;i<=3;i++)
- {
- try
- {
- int a, b;
- Scanner s=new Scanner(System.in);
- System.out.print("請輸入分子: ");
- a=s.nextInt();
- System.out.print("請輸入分母: ");
- b=s.nextInt();
- System.out.println(a+"/"+b+"="+(a/b));
- }
- catch(java.lang.ArtithmeticException e)
- {
- System.out.println("運算錯誤 分母不能為零");
- }
- catch(java.util.InputMismatchException e)
- {
- System.out.println("格式錯誤!請輸入整數");
- }
- if(i==3)
- System.out.println("錯誤多次,跳出程式");
- }
- }
- }
複製代碼 |