public static void main(String[] args) {
//PROBLEM: -300 pops up before program shuts down
// Variables
double celsiusCalculation = 0;
String fahrenheitInput = "";
while (!(fahrenheitInput.equals("-300"))) {
fahrenheitInput = JOptionPane.showInputDialog(null,
"Enter a number (in Fahrenheit) to convert to Celsius:");
double fahrenheit = Double.parseDouble(fahrenheitInput);
celsiusCalculation = (fahrenheit - 32) * 5 / 9;
celsiusCalculation = (int)(celsiusCalculation * 10);
celsiusCalculation = celsiusCalculation / 10.0;
JOptionPane.showMessageDialog(null, celsiusCalculation);
}
}
Hey, guys. I have a slight little problem here with my code. For some reason it calculates the Celsius conversion and gives me the answer, but when I want to input "-300" (to quit the program) it calculates -300 Fahrenheit to Celsius, and then it quits. How can I bypass this?
Thanks!