Skip to content

Instantly share code, notes, and snippets.

@peter279k peter279k/JPA04.java
Created May 24, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.