Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

Commit 98ef33a

Browse files
A java program that calculates the factorial of user given number
1 parent ea006ac commit 98ef33a

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

‎src/navs/program.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ export const programsNav = {
1919
pages['java-program-to-check-divisbility'],
2020
pages['find-quotient-and-reminder'],
2121
pages['calculate-power-of-a-number'],
22+
pages['factorial-in-java'],
2223
],
2324
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Java Program to Calculate Factorial of a number
3+
shotTitle: Calculate Simple Factorial
4+
description: In this program, you'll learn to calculate the factorial and display final value on screen/terminal
5+
---
6+
import {TipInfo} from '@/components/Tip'
7+
8+
To understand this example, you should have the knowledge of the following Java programming topics:
9+
10+
- [Java Loops](/docs/for-loop)
11+
- [Java Basic Input and Output](/docs/basic-input-output)
12+
13+
## Calculate Factorial
14+
15+
A java program that calculate the factorial of a number by getting user input of the number.
16+
17+
```java
18+
import java.util.Scanner;
19+
class FactorialExample{
20+
public static void main(String args[]){
21+
Scanner in = new Scanner(System.in);
22+
int i,fact=1;
23+
int number = in.nextInt();
24+
for(i=1;i<=number;i++){
25+
fact=fact*i;
26+
}
27+
System.out.println("Factorial of "+number+" is: "+fact);
28+
}
29+
}
30+
```
31+
32+
#### Output
33+
34+
```text
35+
Enter the number : 5
36+
The factorial of 5 is : 120.
37+
```
38+
39+
To Calculate Factorial ,
40+
```Factorial(5) = (5*4*3*2*1)```
41+
42+
43+
44+
<TipInfo>
45+
46+
Don't know how to take input from the user ? Look at [this examples](/docs/basic-input-output#java-input)
47+
48+
Here two input numbers are taken from user one after another with space in between them which distinguish between two different inputs, this useful behavior is because of the default settings of Scanner called as Delimiter, [learn more here](https://www.javatpoint.com/post/java-scanner-delimiter-method).
49+
50+
</TipInfo>

0 commit comments

Comments
 (0)