- import java.util.Scanner;
- public class java01 {
- public static void main(String[] args) {
- for (;;)
- {
- try
- {
- Scanner s = new Scanner(System.in);
- int x, y;
- System.out.print("輸入分子");
- x = s.nextInt();
- System.out.print("輸入分母");
- y = s.nextInt();
- System.out.println(x + "/" + y + "=" + (x / y));
- } catch (Exception e) {
- System.out.println("程式發生錯誤");
- System.out.println("例外類別"+e.toString());
- }
- System.out.println();
- }
- }
- }
複製代碼 |