92.4k views
2 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.

User Tssch
by
5.5k points

1 Answer

4 votes

Answer:

Following are the code to this question:

public class fact//defining class fact

{

public static void main(String[] ax) //defining main method

{

int x,f=1;//defining integer variable

System.out.println("Followig are the factorial from 1 to 10: "); //print message

for(x=1;x<=10;x++)//defining for loop to print factorial from 1 to 10

{

f = f*x;//calculating factorial and store value in f variable

System.out.println("Factorial of "+ x+" is: " +f);//print values

}

}

}

Output:

please find the attached file.

Step-by-step explanation:

In the above-given java program, a class "fact" is defined, inside the class main method is declared, in which two integer variable "x and f" is declared, in which the variable "f" holds an integer value that is "1".

In the next step, a for loop is declared, that uses the variable x to calculate the factorial from 1 to 10, and stores it value in f variable, in this loop a print method is used that prints its factorial value.

Write an application that displays the factorial for every integer value from 1 to-example-1
User Brianda
by
4.9k points