Factorial program in Java using recursion.

Java Programming Java8Object Oriented Programming

Following is the required program.

Example

Live Demo

public class Tester {
   public static void main(String args[]) {
      int i, fact = 1;
      int number = 5;
      for (i = 1; i <= number; i++) {
         fact = fact * i;
      }
      System.out.println(number + "! = " + fact);
   }
}

Output

5! = 120
raja
Published on 22-Apr-2018 19:15:58
Advertisements