Answers for "program to find factorial using recursion in java"

1

factorial of a number using recursion in java

public int factorial(int num) {
        if (num == 0)
            return 1;
        else
            return (num * factorial(num - 1));
    }
Posted by: Guest on October-15-2021
0

factorial program in java without recursion

public class Tester {
   static int factorial(int n) {
      if (n == 0)
         return 1;
      else
         return (n * factorial(n - 1));
   }
   public static void main(String args[]) {
      int i, fact = 1;
      int number = 5;
      fact = factorial(number);
      System.out.println(number + "! = " + fact);
   }
}
Posted by: Guest on September-29-2020

Code answers related to "program to find factorial using recursion in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language