Answer:
The program to this question can be given as:
Program:
class Main //define class.
{
public static void main(String args[]) //define main method
{
int i,Factorial=1; //define variable.
for(i=1;i<=10;i++)
// for loop
{
Factorial=Factorial*i; //variable hold value
System.out.println("Factorial of "+i+" is: "+Factorial); //print value
}
}
}
Output:
Factorial of 1 is: 1
Factorial of 2 is: 2
Factorial of 3 is: 6
Factorial of 4 is: 24
Factorial of 5 is: 120
Factorial of 6 is: 720
Factorial of 7 is: 5040
Factorial of 8 is: 40320
Factorial of 9 is: 362880
Factorial of 10 is: 3628800
Explanation:
The description of the above java program can be given as:
In the above factorial program firstly we define the Main class. In this class, we define the main method. Then we define the main method, in this method, we define a variable that is "i and factorial". The variable i is used in the loop and the variable factorial is used for holding factorial value. Then we define for loop it is an entry control loop. In this loop we calculate factorial form numbers 1 to 10. and print the values.