Factorial of a number using Java



Write a program in Java to find the factorial of a number


Program:





class
Sk03


{


  public static void main(String args[])


  {


  short n= 5;


  int fact=1;


  for(int i=1;i<=n;i++)


  {


      fact=fact*i;


  }


  System.out.println("The factorial of
"+n+" is "+fact);


}


}





Compile:


D:\>javac
Sk03.java





Run:


D:\>java
Sk03





Output:


The
factorial of 5 is 120
















Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C