We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e918b31 commit 9965d3aCopy full SHA for 9965d3a
recursiveFactorial.java
@@ -0,0 +1,25 @@
1
+import java.util.Scanner;
2
+
3
+public class recursiveFactorial {
4
5
+ public static void main(String args[]) {
6
+ // Scanner object for capturing the user input
7
+ Scanner scanner = new Scanner(System.in);
8
+ System.out.println("Enter the number:");
9
+ // Stored the entered value in variable
10
+ int num = scanner.nextInt();
11
+ // Called the user defined function fact
12
+ int factorial = fact(num);
13
+ System.out.println("Factorial of entered number is: " + factorial);
14
+ }
15
16
+ static int fact(int n) {
17
+ int output;
18
+ if (n == 1) {
19
+ return 1;
20
21
+ // Recursion: Function calling itself!!
22
+ output = fact(n - 1) * n;
23
+ return output;
24
25
+}
0 commit comments