Toggle navigation
Code Exercises
Interview Planner
Interview Guide
Practice Now
Blog
About
Easy
Moderate
Challenging
Sum of Two Numbers
Sum Multiples of Three and Five
Factorial
Linear Search
Reverse String
Find Maximum
Average Value (Java 8 Lambdas and Streams)
Convert to Upper Case (Java 8 Lambdas and Streams)
Nth Odd Element
Number Of Tree Nodes
Count Nodes in List
Count Number of Leaf Nodes
Binary Tree Depth
Find Second Largest Number in Array
Factorial
Write a method that calculates the factorial of a given number.
Factorial is the product of all positive integers less than or equal to n. For example, factorial(4) = 4x3x2x1 = 24.
TIP: To make it more interesting, try to do it recursively.
public Integer factorial(Integer n) {
}
Submit
Clear
Solution