I wrote this little program to convert celsius to fahrenheit and back in java (I'm teaching myself in my spare time, but I want to get it to restart (loop?) every time its done until someone types 'quit' into the reader. How would I do this?
// Name: Convert (Fahrenheit <-->
// Celsius)
// Description:Convert degrees Celsius
// to degrees Fahrenheit, and vice-versa.
// By: Andrew
import TerminalIO.KeyboardReader;
public class CelsFahr {
public static void main (String[]args)
{
KeyboardReader reader = new KeyboardReader();
int choice = reader.readInt("If you would like to convert from Fahrenheit to Celsius, enter 1. \n"
+ "For Celsius to Fahrenheit, enter 2. ");
if (choice == 1) {
double fahrenheit = reader.readDouble("Degrees fahrenheit: ");
double celsius = (fahrenheit - 32.0) * (5.0 / 9.0);
System.out.println(+ fahrenheit + " degrees Fahrenheit = " + celsius + " degrees Celcius.");
}
if (choice == 2) {
double celsius = reader.readDouble("Degrees Celsius: ");
double fahrenheit = ((9.0/5.0) * celsius) + 32;
System.out.println( celsius + " degrees Celsius = " + fahrenheit + " degrees Fahrenheit.");
}
}
}