Saturday, 17 May 2014

JAVA Program to Find the Factorial of a Number

Factorial of a number USING JAVA

A program to accept a number from keyboard and print the Factorial.


//A small java program to calculate the Factorial
import java.util.Scanner;
public class Factorial
{
public static void main(String[] args)
{           final int fact;
             System.out.println("Enter a number to find the Factorial");
             Scanner in = new Scanner(System.in);
             fact=in.nextInt();
             System.out.println( "Factorial of " + fact + " is " + factorial(fact));
}

public static int factorial(int n)
{ 
             int result = 1;
for(int i = 2; i <= n; i++)
result *= i;
return result;
}

}

Output:


Enter a number to find the Factorial
5
Factorial of 5 is 120

13 comments :

  1. Whoa, amazing blog format! How long are you currently blogging for?
    Your site is great, and articles are superb!

    Feel free to visit my website - phentermine diet pills (www.enhancedonlinenews.com)

    ReplyDelete
  2. The expansion of internet and intelligence in business process lead the way to huge volume of data. It is important to maintain and process these data to be efficient in data handling. Hadoop Training in Chennai | Big Data Training in Chennai

    ReplyDelete
  3. Excellent post!!! Selenium automation testing tool makes software and web application process lot simpler. Keep on updating your blog with such awesome information. Selenium Course in Chennai

    ReplyDelete
  4. Hi,

    Thank you so much for posting this. I really appreciate your work. Keep it up. Great work!

    http://kosmiktechnologies.com/selenium/

    ReplyDelete
  5. Thanks for sharing your valuable ideas and views, it is very useful for me.. keep rocks...
    Java Training institute in velachery | Java Course in chennai

    ReplyDelete
  6. Thanks for posting this amazing article with impressive content.keep sharing your informative post..
    Best Linux Training Institute in Chennai | No.1 Linux Training Center in Chennai | Red Hat Linux Training Center in Chennai

    ReplyDelete