I just started programming yesterday, and I have been making little programs to learn some algorithms and the syntax of java. I tried making a program that could convert metric units into the American system. Whenever I try to compile the code, it shows up as an "incompatible type" error. I know this is probably a very obvious answer to most of you, but I can't figure it out.
import java.util.Scanner;
public class MetricToAmerican
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("\fWhat measurement would you like to convert into US system? \ncelsius, meter, or kilogram ");
String measurement = scan.nextLine();
{
if (measurement = "celsius") {
System.out.println("\fWhat is the temperature in degrees Celsius? ");
double celsius = scan.nextDouble() ;
double fahrenheit = celsius * 1.8 + 32 ;
System.out.println("\fThe temperature is " + fahrenheit + " degrees Fahrenheit");
} else if (measurement = "meter") {
System.out.println("\fWhat is the length in meters? ");
double meter = scan.nextDouble() ;
double feet = meter * 3.28 ;
System.out.println("\fThe length is " + feet + " feet");
} else if (measurement = "gram") {
System.out.println("\fWhat is the weight in kilograms? ");
double kilogram = scan.nextDouble() ;
double pound = kilogram * 2.20462 ;
System.out.println("\fThe weight is " + pound + " pounds");
} else {
System.err.println("PLEASE TYPE CELSIUS METER OR KILOGRAM");
}
}
}
}
So if you know what s wrong with this program can you please say what is wrong and maybe how to fix it so I can learn from my mistakes. Thanks.