Factorial of a number :Unleashed
For factorial of a number recursive program click the given link.
Factorial of a number is the product of the numbers from 1 up to the number.
Write a program to accept a number and print its factorial. For example the factorial of 4 is 24(4 X 3 X 2 X 1)
For factorial of a number recursive program click the given link.
Factorial of a number (Recursive Function)
import java.io.*;
class factorial
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number of your choice");
int n=Integer.parseInt(br.readLine());
int fact=1;
for(int i=1;i<=n;i++)
{
fact*=i;
}
System.out.println("The factorial of the number is"+ fact);
}
}Output: Enter a number of your choice
4
The factorial of the number is 24
To learn how to take input using BufferedReader watch the video
https://youtu.be/bTOMwnwpXqs
Related Posts
Continue learning with these related articles
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.