DeveloperBreeze

Calculate Factorial

public static long factorial(int n) {
    if (n == 0 || n == 1) {
        return 1;
    }
    return n * factorial(n - 1);
}

int number = 5;
long result = factorial(number);
System.out.println("Factorial of " + number + " is " + result);

Related Posts

More content you might like

Tutorial
javascript

Non-Primitive Data Types (Objects, Arrays, and Functions)

Arrays are ordered collections of elements, which can be of any type.

  let fruits = ["apple", "banana", "cherry"];

Dec 11, 2024
Read More
Tutorial
javascript

Easy JavaScript Tutorial for Beginners

for (let i = 0; i < 5; i++) {
    console.log("Iteration: " + i);
}
let i = 0;
while (i < 5) {
    console.log("Iteration: " + i);
    i++;
}

Sep 18, 2024
Read More
Cheatsheet
solidity

Solidity Cheatsheet

  • Use immutable and constant for variables that do not change.

  • Leverage view and pure functions to save gas on reads.

Aug 22, 2024
Read More
Code
javascript

Prime Number Check and Prime Number Generation in JavaScript

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!