Programming





Write a program to find Factorial of a number entered by the user.

Write a program to find Factorial of a number entered by the user.


by Administrator | 19-Apr-2020
Java

Tags:  Program  Java  Factorial

Share: 


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

Comments:


There are no comments.

Enter a new Comment:










Copyright Šprgrmmng. All rights reserved.