Side Navigation


Factorial Sum

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 class BestOnlineLearning {
    public static int factorialSum(int n){
        int sum = 1;
          for(int i = n; i > 0; i--){
              sum = sum * i;
        return sum;

    public static void main(String[] args) { 


You May Also Like


Leave a Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>