import java.util.Scanner;
import java.lang.Math;
public class ConvertTemp
{
public static void main(String[] args)
//try making a program that asks if the user wants to convert f to c or vv
{
//declare variables and instantiate
double temp, fahren, cels;
String tempType;
Scanner input = new Scanner(System.in); //try changing this later
//ask user for data
System.out.print("Is this temperature in fahrenheit or celsius (enter F or C)?");
tempType = input.nextLine();
System.out.println(tempType);
System.out.println(tempType=="F");
if(tempType == " F")
{
System.out.print("Enter your temperature in Fahrenheit: ");
temp = input.nextDouble();
fahren = Math.round((9.0/5.0) * (temp + 32.0));
System.out.println(temp + " degrees fahrenheit is " + fahren);
}
if(tempType == " C")
{
System.out.print("Enter your temperature in Celsius: ");
temp = input.nextDouble();
cels = Math.round((temp - 32.0) * 5.0/9.0); //this will round to one decimal bc float param
System.out.println(temp + " degrees celsius is " + cels);
}
}
}
When I run the program and enter F, this is what shows up:
Is this temperature in fahrenheit or celsius (enter F or C)?F F false
Why is it giving me false? Even before I try running through the if statements?