DEV3.2 TP'S

This commit is contained in:
2025-12-05 10:40:31 +01:00
parent cd5f593c57
commit 3108dea35f
5 changed files with 119 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
public class Recursion {
public static void main(String[] args) {
if(args.length > 0) {
displayFactorial(Integer.parseInt(args[0]));
return;
}
System.out.println("Usage: java Recursion <number>");
}
public static void displayFactorial(int n) {
System.out.println(n + "! = " + factorial(n, 0));
}
private static int factorial(int n, int count) {
count++;
System.out.println("n = " + n + " | count = " + count);
if(n == 0) {
//Thread.dumpStack();
return 1;
}
return n * factorial(n - 1, count);
}
}