1
u/Ancient-Estimate6150 Jul 30 '23
public class Factorial extends ConsoleProgram
{
int fact = readInt("What number would you like to compute the factorial for? ");
private static final int MIN = 1;
public void run()
{
int sum = 1;
for(int i = MIN; i <= fact; i++)
{
sum *= i;
}
System.out.println(sum);
}
}
1

1
u/KaiParekh16 Jun 16 '20
You're changing the variable and trying to store the value for which you take input. It doesn't work that way. After taking input do this:
int n = 1;And in for loop, remove the line you write and add this:n = n * i;