I don't know why I'm spacing out tonight, because I've been doing fine, but I'm stuck on one thing. I've already written the first part of my program (get integer input from the user, then calculate the product, and display), but the second part (not required, but I thought I'd give it a try to find out how it works) says, "If the user enters a number (n) <= 0, you should inform then that this is invalid, and give them another chance to re-enter a number."
Thing is, I'm spacing out on how to go about this - to add it into my existing code. It looks easy, and I'm sure it is, but it's just not coming to me at the moment.
Here's my existing code:
import javax.swing.JOptionPane;
public class Summer
{
public static void main(String args[])
{
int n;
int product = 1;
String input = JOptionPane.showInputDialog(null, "Please enter a number:",
"Summer Program Input", JOptionPane.QUESTION_MESSAGE);
n = Integer.parseInt(input);
for (int i = 1; i <= n; i++)
{
product = product*i;
}
JOptionPane.showMessageDialog(null, "When the number is "+ n + ", the product = " + product,
"Summer Program Product", JOptionPane.INFORMATION_MESSAGE);
}
}
Any suggestions?