### Similar Tutorials

# Calculate Factorial in Java

In this tutorial, we will calculate factorial of an user input (integer) and to do this, we will create a for loop for multiplying numbers

19 January 2020 0 JavaLet's use a for loop and calculate the factorial of user input.

```
Scanner input = new Scanner(System.in);
System.out.println("Type a number to calculate factorial");
int number = input.nextInt();
int factorial = 1;
for (int i=2; i<=number; i++)
factorial*=i;
System.out.println(number+"! = "+factorial);
```

**Output:**

Type a number to calculate factorial

5

5! = 120