Java Programming

  1. Java Program: Factorial
    
    public class Factorial{
        public static void main(String args[]){
            int n=5;
            int fac=1;
             for(int  i=1;i<=n;i++)
             fac=fac*i;
             System.out.println("Factorial of "+n+" is "+fac);
         }
     }
                  
    
  2. Output:
    
    Factorial of 5 is 120
                  
  3. Java Program: Factorial using user input
    
    import java.util.Scanner;
     public class Factorial{
        public static void main(String args[]){
          Scanner sc=new Scanner(System.in);
          System.out.println("Enter Range of Factorial");
          int n=sc.nextInt();
          int fac=1;
          for(int i=1;i<=n;i++)
             fac=fac*i;
           System.out.println("Factorial of "+n+" is "+fac);
        }
    }
                  
              
    
  4. Output:
    
    Enter Range of Factorial
    5
    Factorial of 5 is 120
                
              

Others Programming Language

article

programming C

Muktarul Hossain
article

C++

Muktarul Hossain
article

Python

Muktarul Hossain
article

Website Design

Muktarul Hossain