➤ Check Even Number
➤ Check Odd Number
➤ Java Even-Odd
➤ Greatest of 3 numbers
➤ Exponents in Java
➤ Java Leap Year Program
➤ Display Multiplication Table
➤ Reverse of a number
➤ Factors of a Number
➤ Java LCM of 2 Numbers
➤ Java HCF of 2 Numbers
➤ Quadratic Equation Program
➤ Square Root of Number
➤ Perfect Square Program
➤ Simple Calculator Program
➤ BMI Calculator Java
➤ Factorial of a Number
➤ Factorial Using Recursion
# Java Programs to Find Sum
# Java Conversion Programs
# Java Program on Series
# Java Pattern Programs
# Java Number Programs
Java Array Programs
Java String Programs
Find Factorial From 1 to 10 in Java | In mathematics, the factorial of a positive integer number specifies a product of all integers from 1 to that number. It is defined by the symbol exclamation mark (!).
Formula:- factorial(n) = n * factorial(n-1)
General Case for Finding Factorial
Factorial (n) =
1 * 2 * … * (n-1) * n
Or,
n * (n-1) * … * 2 * 1
Note:- The factorial of a negative number and float number doesn’t exist.
The Base Case for Finding Factorial
factorial(0) = 1
Or,
factorial(1) = 1
For example:- The factorial of 3 = 3! = 321 or 123 = 6
Find Factorial From 1 to 10 in Java
In this program, we will discuss how to find the factorial of the number from 1 to 10. We will use the for loop to find factorial. The for loop calculates the factorial of the number because it uses an increment operator.
public class Factorial {
public static void main(String[] args) {
// declare variables
int count;
long factorial = 1;
// Find factorial from 1 to 10
System.out.printf("%4s%30s\n", "Number", "Factorials");
for(count = 1; count <= 10; count++)
{
factorial *= count;
System.out.printf("%4d%,30d\n", count, factorial);
}
}
}
Output:-
Number Factorials
1 1
2 2
3 6
4 24
5 120
6 720
7 5,040
8 40,320
9 362,880
10 3,628,800
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!