File tree Expand file tree Collapse file tree 1 file changed +0
-20
lines changed
src/main/java/com/thealgorithms/recursion Expand file tree Collapse file tree 1 file changed +0
-20
lines changed Original file line number Diff line number Diff line change 11package com .thealgorithms .recursion ;
22
3- import java .util .Scanner ;
4-
53/**
64 * This class provides a recursive implementation of the factorial function.
7- * The factorial of a number n is defined as n! = n × (n-1) × (n-2) × ... × 1
8- * with the base case 0! = 1.
95 */
106public class Factorial {
117
@@ -25,20 +21,4 @@ public static long factorial(int n) {
2521 }
2622 return n * factorial (n - 1 );
2723 }
28-
29- // Main method with user input
30- public static void main (String [] args ) {
31- Scanner scanner = new Scanner (System .in );
32- System .out .print ("Enter a number to find its factorial: " );
33-
34- int num = scanner .nextInt ();
35- scanner .close ();
36-
37- try {
38- long result = factorial (num );
39- System .out .println ("Factorial of " + num + " is: " + result );
40- } catch (IllegalArgumentException e ) {
41- System .out .println (e .getMessage ());
42- }
43- }
4424}
You can’t perform that action at this time.
0 commit comments