dave on Nostr: public class RecursionExample { public static void main(String[] args) { ...
public class RecursionExample {
public static void main(String[] args) {
System.out.println("Factorial of 4 is: "+factorial(4));
}
static int factorial(int n) {
// Base case
if (n == 0)
return 1;
// Recursive case
else
return(n * factorial(n-1));
}
}
Published at
2023-02-07 16:54:44Event JSON
{
"id": "9a93c24b99e953eb8242a300bb77636692557219877d3475451fe264a5c1699f",
"pubkey": "5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"created_at": 1675788884,
"kind": 1,
"tags": [
[
"e",
"3d36bf9009a0223baa45107fd4d1c13cff51a1fee133fb78fb2ac28df9b6852a",
"",
"reply"
],
[
"p",
"aae9cfdb3113db442c1ad8d4c670a28091e5267748e71d2c1e189e423dbea1bf"
]
],
"content": "public class RecursionExample {\n \n public static void main(String[] args) {\n System.out.println(\"Factorial of 4 is: \"+factorial(4));\n }\n \n static int factorial(int n) { \n // Base case\n if (n == 0) \n return 1;\n \n // Recursive case\n else\n return(n * factorial(n-1));\n }\n \n}",
"sig": "31de6cffb584e0f1524eeb535d3352e6c1b349af424c1d57218be76ab2e76bc9cb0fe4445dd4ddc9cc0dff2d3d0d12a6e0ca876554aad7e9ec46fa07b8c777c7"
}