Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Java Program to Calculate The Factorial Number

Hi friend, hope you are doing good. In today’s tutorial, I am going to share a very useful java program to calculate the factorial number of any given number. If you are looking for how to write a program to calculate factorial number using Java programming language.

Java program to Calculate The Factorial Nunber

Copy the below program and execute it with the help of Java compiler to calculate factorial numbers.

import java.util.Scanner;
 
class Factorial
{
   public static void main(String args[])
   {
      int n, c, fact = 1;
 
      System.out.println("Enter an integer to calculate the factorial:");
      Scanner in = new Scanner(System.in);
 
      n = in.nextInt();
 
      if ( n 

Program Output

Enter an integer to calculate the factorial:
-10
Entered number shouldn’t be negative.
#second try
Enter an integer to calculate the factorial:
5
Factorial of 5 is: 120

The post Java Program to Calculate The Factorial Number appeared first on FreeWebMentor.



This post first appeared on Programming Blog Focused On Web Technologies, please read the originial post: here

Share the post

Java Program to Calculate The Factorial Number

×

Subscribe to Programming Blog Focused On Web Technologies

Get updates delivered right to your inbox!

Thank you for your subscription

×