Write a program to print factorial of a number in Java

The following is the code for printing Factorial  of a number.

Code:
 import java.util.Scanner;  
 public class Factorial {  
      public static void main(String args[])  
      {     int num;  
           Scanner in=new Scanner(System.in);  
           System.out.println("Enter a Number");  
           num=in.nextInt();  
           System.out.println("Factorial of "+num+" is : "+findFact(num));  
      }  
      public static int findFact(int num)  
      {  
           int fact=1;  
           for(int i=1;i<=num;i++)  
                fact=fact*i;  
           return fact;  
      }  
 }  
Output :
Enter a Number
5
Factorial of 5 is : 120

No comments: