Any idea on how I can fix this? I'm telling the user to enter the amount of numbers he would like to average. Of course as you can see in the code, if he inputs a 0 or a negative number I want it to flag the user to enter another number that is not 0 or a negative number. The problem is, once the user puts a 0 or a negative number, it gets stuck in that state and I have to terminate the program.
Help?
import javax.swing.JOptionPane;
public class TestProgTres
{
public static void main(String[] args)
{
//Variable Declaration
String ShowSome;
String ShowSomeAgain;
int z = 0;
double avg = 0;
double totalamt = 0;
ShowSome = JOptionPane.showInputDialog("Enter the amount of numbers you would like to average");
double AllNumbers = Double.parseDouble(ShowSome);
while (AllNumbers < 1)
{
JOptionPane.showInputDialog("You cannot enter a negative or a 0. Enter the amount of numbers you would like to average");
AllNumbers = Double.parseDouble(ShowSome);
}//end while
if (AllNumbers > 0)
{
double Numbers [] = new double [(int) AllNumbers];
for (z = 0; z < Numbers.length; z++)
{
ShowSomeAgain= JOptionPane.showInputDialog("Enter number " + (z + 1));
Numbers[z]=Double.parseDouble(ShowSomeAgain);
totalamt += Numbers[z];
avg = totalamt/AllNumbers;
}
}
JOptionPane.showMessageDialog(null, "The of the numberes entered is " + avg);
}//end main
}// end class
ShowSomeand are ignoring the results fromJOptionPane.showInputDialog