Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created May 24, 2017 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter279k/8f188820c8d9116f5453d459f4c8d31b to your computer and use it in GitHub Desktop.
Save peter279k/8f188820c8d9116f5453d459f4c8d31b to your computer and use it in GitHub Desktop.
TQC+ JAVA
import java.util.Scanner;
public class JPA03 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
System.out.print("Input n (0 <= n <= 16):");
int num = keyboard.nextInt();
int sum = 1;
while(true) {
if(num > 16 || num < 0 || num == 999) {
break;
}
System.out.println(num + " 的階乘 = " + factorial(num, sum));
System.out.print("Input n (0 <= n <= 16):");
num = keyboard.nextInt();
}
}
public static int factorial(int num, int sum) {
if(num == 0) {
return sum;
}
return factorial(num-1, num * sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment