Q:

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

0

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

All Answers

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

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:

Enter any positive integer: 5

Factorial: 120

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

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a Java program that prompts the user to inpu... >>
<< Write a Java program to print multiplication table...