Java program for factorial of any number

Java program for factorial of any number 

import java.util.Scanner;
public class Factorial 
{
   public static void main(String args[ ])
   {
     Scanner s=new Scanner(System.in);
     int i , n, fact=1;
     System.out.println("Enter any number");
     n=s.nextInt();
    
     for(i=1;i<=n; i++)
      fact=fact*i;
      System.out.println("Factorial of given number. :"+fact);
     }
   }


Output 

Enter any number 
3
Factorial of given number  :6

 

Comments