Posted: Thu Feb 09, 2006 6:01 pm Post subject: Why wont this loop properly?
I am having trouble getting this to loop properly. I want it to loop until they enter a proper time under 4.5 seconds. When I enter it, it just ends the program.
Thanks
code:
import javax.swing.*;
public class height {
public static void main (String[]args) {
double time, answer;
String inputStr;
inputStr = JOptionPane.showInputDialog(null, "Enter a time less then 4.5 seconds");
time = Double.parseDouble(inputStr);
while (time >4.5){
if (time <= 4.5) {
answer = 100-4.9*time*time;
JOptionPane.showMessageDialog(null,"The height of the object is: " +answer);
} else {
JOptionPane.showMessageDialog(null,"please enter a valid number under 4.5");
}
}
}
}
Sponsor Sponsor
Hikaru79
Posted: Thu Feb 09, 2006 6:11 pm Post subject: (No subject)
Look at the following two lines, as you wrote them in your program: