ICSE Class 10 Computer Applications
Question 71 of 76
Revising Basic Java Concepts — Question 75
Back to all questions 75
Question Question 52
Write a program to print factorial of a given number.
import java.util.Scanner;
public class KboatFactorial
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = in.nextInt();
long f = 1;
for (int i = 1; i <= n; i++) {
f *= i;
}
System.out.println("Factorial of " + n
+ " = " + f);
}
}Output
