kev269
12-03-2004, 11:55 AM
Hi,
The following code loops the InputDialog box and adds the entered numbers to the 'total' variable and displays the total at the end. I want to loop the current loop so that once its broken up (by entering -1), i want it to run the current loop over again (asking to input a number whilst keep adding to the total). I want to be done repeatedly until i type in a number so that it breaks from both loops. im not sure what i have to do to do this and im really new to java. Thanks a lot in advance.
final int SENTINEL = -1
while (latestNum != SENTINEL)
{
if (latestNum <= 6 )
System.out.println(latestNum + " Runs Scored!");
else
JOptionPane.showMessageDialog(null,"Please Enter Number Between 1 - 6");
total = total + latestNum;
str = JOptionPane.showInputDialog("Next Points?");
latestNum = Integer.parseInt(str);
}
System.out.println("He Is Out!");
The following code loops the InputDialog box and adds the entered numbers to the 'total' variable and displays the total at the end. I want to loop the current loop so that once its broken up (by entering -1), i want it to run the current loop over again (asking to input a number whilst keep adding to the total). I want to be done repeatedly until i type in a number so that it breaks from both loops. im not sure what i have to do to do this and im really new to java. Thanks a lot in advance.
final int SENTINEL = -1
while (latestNum != SENTINEL)
{
if (latestNum <= 6 )
System.out.println(latestNum + " Runs Scored!");
else
JOptionPane.showMessageDialog(null,"Please Enter Number Between 1 - 6");
total = total + latestNum;
str = JOptionPane.showInputDialog("Next Points?");
latestNum = Integer.parseInt(str);
}
System.out.println("He Is Out!");