Skip to content

Commit

Permalink
Create P02_RecursiveFactorial.java
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlanasieber authored May 28, 2024
1 parent e9bdf41 commit 037f3d5
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.util.Scanner;

public class P02_RecursiveFactorial {
public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int n = Integer.parseInt(scanner.nextLine());

System.out.println(calcFact(n));

}

public static long calcFact(int n) {

if (n == 1 || n == 0) {
return 1;
}

return n * calcFact(n - 1);
}
}

/*import java.util.Scanner;
public class P02_RecursiveFactorial {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = Integer.parseInt(scanner.nextLine());
System.out.println(factorial(n));
}
private static int factorial(int n) {
if (n == 0) {
return 1;
}
return n * factorial(n - 1);
}
}*/

0 comments on commit 037f3d5

Please sign in to comment.