Finding Factorials Using Recursion in Java

Problem:

Write a recursive method that find factorials in Java.

Output:

None

Solution:

public class Factorial
{
  public static int factorial(int n)
  {
    if (n == 0)
      return 1;
        else
      return n * factorial(n - 1);
  }
}


No comments :

Post a Comment

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact