Factorial program in Java

 import java.util.Scanner;  
 public class Factorial{  
      public static void findFactorial(int number){  
           int factorial=1;  
           do{  
                factorial*=number;  
                number--;  
           }while(number>=2);  
           System.out.println(factorial);  
      }  
      public static void main(String[] args) {    
           Scanner sc=new Scanner(System.in);  
           System.out.println("Enter the number");  
           int number=sc.nextInt();  
           findFactorial(number);  
           sc.close();  
 }  
 }  

Output: Enter the number : 4
24

Comments

Popular posts from this blog

Reasoning-Number Series

Reasoning-Letter Series

Profit and Loss