Write a Java Program to find Factorial using While loop

By | 20.01.2017

Write a Java Program to find Factorial using While loop


Factorial of any number is the product of an integer and all the integers below it

For example ::  factorial of 5 is 5! =5* 4 * 3 * 2 * 1 = 120.

In below source code i will show you how to Write a  Java program to find factorial using while loop.

 

SOURCE CODE ::

 

import java.util.Scanner;

public class Factorial{

    public static void main(String[] args) 
    {
        
        int n, fact=1;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter any number :");
        n=sc.nextInt();
        
        int i=1;
        while(n>=i)
        {
            fact=fact*i;
            i++;
        }
        System.out.println("Factorial is :" +fact);
    }
        
    }

 

OUTPUT ::

 

Enter any number :
9
Factorial is :362880

 

5 2 votes
Article Rating
Category: Basic Programs Java Programming Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments