exo1 ok
This commit is contained in:
parent
75089e6bf4
commit
ef2317ac61
@ -2,4 +2,24 @@ package TP1;
|
||||
|
||||
public class Factorielle {
|
||||
|
||||
public static int fact(int n) {
|
||||
if(n < 0) {
|
||||
return (int)Math.pow(-1, Math.abs(n)) * fact(Math.abs(n));
|
||||
} else if (n == 0){
|
||||
return 1;
|
||||
} else {
|
||||
return n * fact(n-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(fact(-1));
|
||||
System.out.println(fact(-3));
|
||||
System.out.println(fact(-4));
|
||||
System.out.println(fact(-5));
|
||||
System.out.println(fact(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user