Q:

Write a Java Program to find Factorial using While loop

belongs to collection: Java Basic Solved Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a Java Program to find Reverse Number using ... >>
<< Write a Java Program to Check input number is Even...