Write a Java program to find the factorial value of any number entered through the keyboard using loop
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
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
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..
Result:
Enter any positive integer: 5
Factorial: 120
need an explanation for this answer? contact us directly to get an explanation for this answer