# Java program to print the factorial of the given number

Java Programming Java8Java Technologies

#### Complete Java Programming Fundamentals With Sample Projects

98 Lectures 7.5 hours

#### C Programming from scratch- Master C Programming

Best Seller

60 Lectures 8 hours

#### C++ Programming

238 Lectures 56.5 hours

Factorial of a positive integer n is the product of all values from n to 1. For example, the factorial of 3 is (3 * 2 * 1 = 6).

## Algorithm

1. Take integer variable A
2. Assign a value to the variable
3. From value, A up to 1 multiply each digit and store
4. The final stored value is factorial of A

## Example

import java.util.Scanner;
public class Factorial {
public static void main(String args[]){
int i, factorial=1, number;
System.out.println("Enter the number to which you need to find the factorial:");
Scanner sc = new Scanner(System.in);
number = sc.nextInt();

for(i = 1; i<=number; i++) {
factorial = factorial * i;
}
System.out.println("Factorial of the given number is:: "+factorial);
}
}

## Output

Enter the number to which you need to find the factorial:
25
Factorial of the given number is:: 2076180480