Created
May 24, 2017 14:38
-
-
Save peter279k/8f188820c8d9116f5453d459f4c8d31b to your computer and use it in GitHub Desktop.
TQC+ JAVA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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