- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram23_Factorial.java
More file actions
Latest commit
21 lines (18 loc) · 611 Bytes
/
Copy pathProgram23_Factorial.java
File metadata and controls
21 lines (18 loc) · 611 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Write a java program to find the factorial of a number entered by the user.
// Date : 13/03/2024, Author : Yash Wadhvani
importjava.util.Scanner;
publicclassProgram23_Factorial {
staticintfact(inti) {
if (i == 1 || i == 0) {
return1;
}
returni * fact(i - 1);
}
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
System.out.println("Enter a Number to find it's Factorial :");
intnum = sc.nextInt();
sc.close();
System.out.println("Factorial of " + num + " = " + fact(num));
}
}