Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created May 24, 2017 14:26
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/d003fada86688e467daed79a8e7fca06 to your computer and use it in GitHub Desktop.
Save peter279k/d003fada86688e467daed79a8e7fca06 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));
System.out.print("Input n (0 <= n <= 16):");
num = keyboard.nextInt();
}
}
public static int factorial(int num) {
if(num == 0) {
return 1;
}
return num * factorial(num-1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment