- import java.util.Scanner;
- public class Ch01{
- static Scanner s=new Scanner(System.in);
- publc static void main(String[] args) throws Exception{
- float x,y;
- System.out.print("輸入分子: ");
- x=s.nextFloat();
- System.out.print("輸入分母: ");
- y=s.nextFloat();
- if(y==0)
- throw new Exception("分母不可為零");
- System.out.println(x+"/"+y+"="+(x/y));
- }
- }
- class MyException extends Exception
- {
- MyException(String str) {
- super(str);
-
- }
- }
複製代碼 |