JAVA實例:利用遞歸方法求5!
程序分析:遞歸公式:fn=fn_1*4!
import java.util.Scanner;
publicclass Ex22 {
publicstaticvoid main(String[] args) {
Scanner s =
new Scanner(System.
in);
int n = s.nextInt();
Ex22 tfr =
new Ex22();
System.
out.println(tfr.recursion(n));
}
publiclong recursion(
int n) {
long value = 0 ;
if(n ==1 || n == 0) {
value = 1;
}
elseif(n > 1) {
value = n * recursion(n-1);
}
return value;
}
}
*