/*********************************************************** write by tjm 用來展示recursive method ***********************************************************/ import java.io.*; public class demo22{ public static void main(String args[]) throws Exception { //程式進入點 String getbr; BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); int x; /*****請使用者輸入選項**********/ x=5; while (x>=0) { System.out.print("請輸入要計算階乘的數字:"); getbr = br.readLine(); x=Integer.parseInt(getbr); if (x<0) { System.out.println("謝謝!再見!"); continue; } System.out.println(x+ "!="+fraction(x)); } //while結束 } //main 結束 private static int fraction(int y) { int ans; ans=1; if (y<=1) ans=1; else ans=y*fraction(y-1); return(ans); } // fraction 結束 }