tp recursivite

This commit is contained in:
Simoes Lukas
2025-10-09 12:11:25 +02:00
parent 56258c01e6
commit 91d20e0ba6
15 changed files with 181 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,17 @@
public class Factorielle {
public static int factorielle(int n, int indentation) {
for (int i = 0; i != indentation; i++) {
System.out.print(" ");
}
System.out.println("Valeur de n : " + n);
if (n == 1) {
return 1;
}
for (int i = 0; i != indentation; i++) {
System.out.print(" ");
}
System.out.println("Valeur renvoyée : " + n + factorielle(n - 1, indentation++));
return n * factorielle(n - 1, indentation++);
}
}

Binary file not shown.

View File

@@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
System.out.println(Integer.parseInt(args[0]) + "! = " + Factorielle.factorielle(Integer.parseInt(args[0]), 0));
}
}