Skip to content

Commit fa3da3d

Browse files
factorialno
java program
1 parent 7f1df0c commit fa3da3d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

factorialno

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package Edureka;
2+
import java.util.Scanner;
3+
public class Factorial {
4+
public static void main(String args[]){
5+
//Scanner object for capturing the user input
6+
Scanner scanner = new Scanner(System.in);
7+
System.out.println("Enter the number:");
8+
//Stored the entered value in variable
9+
int num = scanner.nextInt();
10+
//Called the user defined function fact
11+
int factorial = fact(num);
12+
System.out.println("Factorial of entered number is: "+factorial);
13+
}
14+
static int fact(int n)
15+
{
16+
int output;
17+
if(n==1){
18+
return 1;
19+
}
20+
//Recursion: Function calling itself!!
21+
output = fact(n-1)* n;
22+
return output;
23+
}
24+
}

0 commit comments

Comments
 (0)