Computer Applications
Answer
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);
}
}
Variable Description Table
Program Explanation
Output
Related Questions
Write a program to print Fibonacci series : 0, 1, 1, 2, 3, 5, 8….
Write a program to input a number in the range 10 to 100 and check if it is a prime number.
Write a program to print following series of numbers: 2, 5, 8, 11, 14….
Write a program to print Floyd's triangle as shown below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15