我得到错误:
表达非法的开始,没有if and If nif and nifegal声明开始。
这是代码:
import java.util.Scanner;
public class Temperature_Converter {
public static void main(String[] args) {
System.out.println("Welcome!This program takes temperature as an input and an input" +
" indicating wether we're converting from Celsius to Fahrenheit or Fahrenheit to Celsius");
Scanner scan = new Scanner (System.in);
System.out.println("Please enter "C" if we're converting from Fahrenheit");
System.out.println("Please enter "F" if we're converting from Celsius");
String temp_key = scan.nextLine();
System.out.println("Please enter the numerical value of the temperature");
double temp_value = scan.nextDouble();
if (temp_key.equals("F"));
{
{
double result = temp_value - 32 / 1.8;
System.out.println("When converting " + temp_value + "Fahrenheit to Celsius,n" +
" the result is " + result);
}
else if (temp_key.equals("C")
}
double result = temp_value * 1.8 + 32;
System.out.println("When converting " + temp_value + "From Celsius to Fahrenheit,n + ");
"the result is;"+ result;);
}
static {;
System.out.println("Next time make sure you enter either F or C");
}
}
丢失半隆和双嵌套卷曲支撑块
这个:
if (temp_key.equals("F"));
{
{
double result = temp_value - 32 / 1.8;
应该是:
if (temp_key.equals("F"))
{
double result = temp_value - 32 / 1.8;
我在这里...
此语句:
double result = temp_value - 32 / 1.8;
不像您认为的那样从F转换为C。32/1.8首先评估。(就像您在9年级代数中学到的一样(。你想说:
double result = (temp_value - 32) / 1.8;