I would have used another approach, to gather user selections:
import java.util.Scanner;
public class TempConverter
{
public static double celsiusToFahrenheit( double celsius)
{
return (celsius * 9.0 / 5.0 + 32.0);
}
public static double fahrenheitToCelsius( double fahrenheit)
{
return ((fahrenheit-32) * 5.0 / 9.0);
}
public static void main( String[] args )
{
Scanner scan = new Scanner(System.in);
while (true)
{
System.out.println("Choose:\n'F' to enter a temperature in Fahrenheit. \n'C' to enter a temperature in Celsius\nAny other character to quit");
String choice = scan.next();
if ( choice.equals("F") )
{
System.out.println("Enter the temperature in Fahrenheit degrees");
double fahrenheit = scan.nextDouble();
System.out.printf("%.2f Fahrenheit degreees are %.2f Celsius degrees\n", fahrenheit, fahrenheitToCelsius(fahrenheit));
}
else if ( choice.equals("C") )
{
System.out.println("Enter the temperature in Celsius degrees");
double celsius = scan.nextDouble();
System.out.printf("%.2f Celsius degreees are %.2f Fahrenheit degrees\n", celsius, celsiusToFahrenheit(celsius));
}
else
break;
}
}
};