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
Updated on 05-Mar-2020 12:17:30

Advertisements