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

17 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
    Replies
    1. Great post.Thanks for one marvelous posting! I enjoyed reading it;The information was very useful.Keep the good work going on!!

      ETL Testing training in chennai| SAP MM training in chennai | Informatica training in chennai

      Delete
  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
  7. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
    aws training in Chennai

    ReplyDelete
  8. Those guidelines additionally worked to become a good way to
    recognize that other people online have the identical fervor like mine
    to grasp great deal more around this condition.

    white label website builder

    ReplyDelete
  9. Nice and good article. It is very useful for me to learn and understand easily...DotNet Project Center in Chennai | DotNet Project Center in Velachery

    ReplyDelete