tp recursivite
This commit is contained in:
17
DEV3.2/TP02/01_Appels/Factorielle.java
Normal file
17
DEV3.2/TP02/01_Appels/Factorielle.java
Normal 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++);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user