64.7k views
4 votes
Write an application that displays the factorial for every integer value from 1 to 10. A factorial of a number is the product of that number multiplied by each positive integer lower than it. For example, 4 factorial is 4 * 3 * 2 * 1, or 24. The output would then be The factorial of 4 is 24. how i do solve this Java Programming Problem?

User Tim Visser
by
4.6k points

1 Answer

7 votes

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.

User Uzilan
by
5.3k points