DEV/DEV3.2/TP2/Appels.java

30 lines
767 B
Java
Raw Permalink Normal View History

2023-10-12 12:26:02 +02:00
public class Appels {
public static int indentation;
public static long fact(long n){
for (int i = 0; i < indentation; i++) {
System.out.print(" ");
}
System.out.println("Argument début: "+n);
indentation++;
if(n==1l){
//Thread.dumpStack();
return 1;
}else{
long r=n*fact(n-1l);
for (int i = 0; i < indentation-1; i++) {
System.out.print(" ");
}
indentation--;
System.out.println("Argument fin: "+r);
return r;
}
}
public static void main(String args[]){
long x=Long.parseLong(args[0]);
indentation=0;
System.out.println(x+"! = "+fact(x));
}
}