Skip to content

Commit eed44ce

Browse files
authored
Merge pull request namishkhanna#191 from drpipy/patch-3
Create factorial.java
2 parents 5b286b4 + fcb9ffd commit eed44ce

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

FactorialDemo.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.Scanner;
2+
class FactorialDemo{
3+
public static void main(String args[]){
4+
Scanner scanner = new Scanner(System.in);
5+
System.out.println("Enter the number:");
6+
int num = scanner.nextInt();
7+
int factorial = fact(num);
8+
System.out.println("Factorial of entered number is: "+factorial);
9+
}
10+
static int fact(int n)
11+
{
12+
int output;
13+
if(n==1){
14+
return 1;
15+
}
16+
output = fact(n-1)* n;
17+
return output;
18+
}
19+
}

0 commit comments

Comments
 (0)