Using loops to compute factorial numbers, Java
I'm trying to compute the value of 7 factorial and display the answer, but
when I tried to look up a way to do this I kept finding code that was
written so that a number first had to be put in from the user and then it
would factor whatever number the user put in. But I already know what
number I need, obviously, so the code is going to be different and I'm
having trouble figuring out how to do this.
I tried this at first
public class Ch4_Lab_7
{
public static void main(String[] args)
{
int factorial = 7;
while (factorial <= 7)
{
if (factorial > 0)
System.out.println(factorial*facto…
factorial--;
}
}
}
But all it does is display 7*7, then 6*6, then 5*5, and so on, and this
isn't what I'm trying to do. Does anyone know how to do it correctly?
No comments:
Post a Comment