Created
May 24, 2017 14:26
-
-
Save peter279k/d003fada86688e467daed79a8e7fca06 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)); | |
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