Alrighty, I'm new in java and I'm having a bit of an issue getting this loop to do what I want. I've tried organizing them in just about every way, with different results, but not what it's supposed to be. It's supposed to be a factorial finding application.
I'm working in Netbeans. I want it to display the answers and keep asking for another number to find the factorial for as long as the user inputs a valid number. If the number entered is a negative number, I want it to say it can't find the factorial and to enter another number. If the number entered is zero, I want the answer to be given, and then the application terminated. Right now, if I enter a number it will find the factorial and ask for another number but if I enter another number it will think I entered a 0.
Enter a number to find the factorial:5
5
20
60
120
120
Factorial of 5 is 120
Enter another number or 0 to quit:
5
The factorial of 0 is 1. Terminating application.
(also, don't know if the extra 120 is necessary, and if I could cut that out that would be great!)
If I enter a 0, it will still ask for another number and then say number I entered was zero.
Enter a number to find the factorial:0
Factorial of 0 is 1
Enter another number or 0 to quit:
5
The factorial of 0 is 1. Terminating application.
Then when I enter a negative number, the second number will ultimately give me what I need on the first number.
run:
Enter a number to find the factorial:-9
Factorial of -9 is 1
Enter another number or 0 to quit:
5
Cannot compute. Enter a number greater than 0.
I have been mulling over this all week, any help would be appreciated!!
I'm working in Netbeans. I want it to display the answers and keep asking for another number to find the factorial for as long as the user inputs a valid number. If the number entered is a negative number, I want it to say it can't find the factorial and to enter another number. If the number entered is zero, I want the answer to be given, and then the application terminated. Right now, if I enter a number it will find the factorial and ask for another number but if I enter another number it will think I entered a 0.
Enter a number to find the factorial:5
5
20
60
120
120
Factorial of 5 is 120
Enter another number or 0 to quit:
5
The factorial of 0 is 1. Terminating application.
(also, don't know if the extra 120 is necessary, and if I could cut that out that would be great!)
If I enter a 0, it will still ask for another number and then say number I entered was zero.
Enter a number to find the factorial:0
Factorial of 0 is 1
Enter another number or 0 to quit:
5
The factorial of 0 is 1. Terminating application.
Then when I enter a negative number, the second number will ultimately give me what I need on the first number.
run:
Enter a number to find the factorial:-9
Factorial of -9 is 1
Enter another number or 0 to quit:
5
Cannot compute. Enter a number greater than 0.
I have been mulling over this all week, any help would be appreciated!!