I need to modify my program so that I can run it more than once if need be. I need to quit the program if the user enters a Q or q and if anything other than the requested entry (or the quit command) is entered the question will be repeated. Here is the code I have so far:
import java.util.Scanner;
public class TemperatureLoop
{
private static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args)
{
System.out.println("Enter a temperature in degrees (for example 32.6): ");
double temp;
temp = keyboard.nextDouble();
System.out.println("Enter 'F' (or 'f') for Fahrenheit or 'C' (or 'c') for Celsius: ");
String letter = keyboard.next();
double total = 0;
//if Farenheit then do this equation
if (letter.equals("F") || (letter.equals("f")))
{
total = ((temp-32)*5)/9; //convert the entered temperature to Celsius
System.out.println(temp + " degrees F = " + total + " degrees Celsius");
}
else //if Celsius then do this
if (letter.equals("C") || (letter.equals("c")) )
{
total = (((temp*9))/5)+32; //convert the entered temperature to Farenheit
System.out.println(temp + " degrees C = " + total + " degrees Fahrenheit");
}
}
}