TQC+ JAVA 401 第迴階層計算
import java.util.Scanner;public class JPA04 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
int n;
while(true){
System.out.print("Input n ( 0 <= n <=16 ):");
n=keyboard.nextInt();
if(n==999 ) break;
System.out.printf("%d 的階乘= %d %n",n,fac(n));
}
}
static int fac(int a){
if(a==0)
return 1;
else
return fac(a-1)*a;
}
}
沒有留言:
張貼留言