fin des tp
This commit is contained in:
28
DEV3.2/Recursiviote/Appel.java
Normal file
28
DEV3.2/Recursiviote/Appel.java
Normal file
@@ -0,0 +1,28 @@
|
||||
public class Appel{
|
||||
public static int fact(int a, int indentation) {
|
||||
int i;
|
||||
for (i = 0; i < indentation; i++)
|
||||
System.out.print(" ");
|
||||
System.out.println("argument ="+a);
|
||||
if (a == 1) {
|
||||
return 1;
|
||||
} else {
|
||||
int res = a * fact(a-1, indentation+1);
|
||||
for (i = 0; i < indentation; i++)
|
||||
System.out.print(" ");
|
||||
System.out.println("resultat ="+res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] argv){
|
||||
if (argv.length < 1){
|
||||
System.err.println("manque un nombre pour le calcul");
|
||||
} else {
|
||||
int ind = 0;
|
||||
int n = Integer.parseInt(argv[argv.length-1]);
|
||||
int res = fact(n, ind);
|
||||
System.out.println(n+"! = "+res);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user