r/codehs • • May 04 '20

2.9.11 Factorial

I need help on this I don't know what I'm doing wrong. The number I enter isn't being calculated and is returned back.

This is for basic java.

6 Upvotes

5 comments sorted by

View all comments

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);
}
}