package com.tedu;
import java.util.Scanner;
/**
* 需求:for循環法(非遞歸)求階乘
* @author CGB
*
*/
public class Test02FDGJC {
public static void main(String[] args) {
System.out.print("請輸入一個整數:");
double x = new Scanner(System.in).nextDouble();
f(x);
System.out.println(x+"的階乘爲:"+f(x));
}
private static double f(double x) {
for (double i = x-1; i >0; i--) {
x=x*i;
}
return x;
}
}