Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

factorial

Article:
Viewed:  3342 
Posted On:  23/07/2013 21:50:24 
In this article i am going to tell u about how we can find out the factorial of the number in java 

 

Below is my code:


import java.util.Scanner;
class factorial
{
    public static void main(String s[])
    {
    int a,b,c=1;
    System.out.println("enter no. ");
    Scanner scan=new Scanner(System.in);
    a=scan.nextInt();
    System.out.println("you entered"+a);
    for(b=a;b>0;b--)
    {
    c=c*b;
    }
    System.out.println("factorial "+c);
    }
}

       Step 1:  After writing this in notepad save the file with the name followed by (.java) for eg. I saved it with factorial.java
 
  Step 2 : 
Open command prompt 
 
  Step 3 : Write javac factorial.java - Press Enter for compilation

  Step 4 : 
Write java factorial for execution 

Now output:

fact.png

Image 1.

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us