From ef2317ac612d0e144a4f850ede3faa0fb40dc01c Mon Sep 17 00:00:00 2001 From: JunkJumper Date: Wed, 2 Sep 2020 14:12:35 +0200 Subject: [PATCH] exo1 ok --- src/TP1/Factorielle.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/TP1/Factorielle.java b/src/TP1/Factorielle.java index 01cd2b4..08018ea 100644 --- a/src/TP1/Factorielle.java +++ b/src/TP1/Factorielle.java @@ -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)); + } } + +