I need a program that will return an integers factorial, but only when the number entered is between 0 and 20. I have the code to disregard anything below 0 and above 20, but something with my math and/or syntax is off and I dont fully comprehend how to fix the error. My code is below....
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
int num; // number to find factorial of
long fac; // factorial so far
Scanner scan = new Scanner(System.in);
// Get value to compute factorial of
System.out.print("Please enter a non-negative integer: ");
num = scan.nextInt();
// Compute and print factorial
// your code here...
while(num < 0 || num > 20){
System.out.println("Factorial is undefined for negative or large numbers");
System.out.print("Please enter an integer number between 0 and 20: ");
num = scan.nextInt();
}
// while(num > 0 || num < 20) {
// for (int i = 1; i < 50; i ++){
// fac = num(i) * num(i -1);
// }
for (int i = 1 ; i <= 20; i++){
num=num - 1 * i;
}
System.out.println("The factorial is: " + num);
}
}
}