From 8c13bb076ae582a046a52c1245ca780a3732fe8b Mon Sep 17 00:00:00 2001 From: zanninso <47645687+zanninso@users.noreply.github.com> Date: Fri, 3 May 2024 09:25:37 +0100 Subject: [PATCH] CON-2569-Markdown-Factorial-exercise (#2530) * docs: adding subject * docs: adding egde case note --- subjects/java/checkpoints/factorial/README.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 subjects/java/checkpoints/factorial/README.md diff --git a/subjects/java/checkpoints/factorial/README.md b/subjects/java/checkpoints/factorial/README.md new file mode 100644 index 000000000..349d7f5c3 --- /dev/null +++ b/subjects/java/checkpoints/factorial/README.md @@ -0,0 +1,40 @@ +## Factorial + +### Instructions + +In a file named `Factorial.java` write a function `factorial` that calculates the factorial of a non-negative integer given as a parameter. + +> The factorial of a non-negative integer n (denoted as n!) is the product of all positive integers less than or equal to n. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120. + +> Note: The factorial of 0 is 1, according to the [convention](https://www.chilimath.com/lessons/intermediate-algebra/zero-factorial/) + +### Expected Functions + +```java +public class Factorial { + public static Integer factorial(Integer n) { + // your code here + } +} +``` + +### Usage + +Here is a possible `ExerciseRunner.java` to test your function : + +```java +public class ExerciseRunner { + public static void main(String[] args) { + System.out.println(Factorial.factorial(3)); + } +} +``` + +and its output : + +```shell +$ javac *.java -d build +$ java -cp build ExerciseRunner +6 +$ +```