Programming |
In mathematics, the factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 5! = 5 x 4 x 3 x 2 x 1 = 120
Program
public class FactorialProgram { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter the number:"); int number = sc.nextInt(); int i = 1; while (number > 0) { i = i * number; number--; } System.out.println("Factorial Value: " + i); } }
Output
Enter the number:10 Factorial Value: 3628800