/*********************************************************** write by tjm 用來展示 return ***********************************************************/ import java.io.*; public class demo16{ 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 i,ans; ans=1; for (i=1;i<=y;i=i+1) { ans=ans*i; } // for 結束 return(ans); } // fraction 結束 }