Write a Java program to find the factorial value of any number entered through the keyboard using loop

Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..

import java.util.Scanner;
 
public class JavaLoopExcercise
{
    public static void main(String[] args)
    {
        Scanner console = new Scanner(System.in);
        int num; 
        int fact = 1; 
 
        System.out.print("Enter any positive integer: ");
        num = console.nextInt();
 
        for(int i=1; i<=num; i++)
        {
            fact *= i;
        }
 
        System.out.println("Factorial: "+ fact);
    }
} 

Result

Write a Java program to find the factorial value of any number entered through the keyboard using loop
Write a Java program to find the factorial value of any number entered through the keyboard using loop

Leave a Comment