28 lines
841 B
Java
28 lines
841 B
Java
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);
|
|
}
|
|
}
|
|
} |