【发布时间】:2011-10-12 00:05:05
【问题描述】:
以下代码出错:
import java.util.Scanner;
public class FahrenheitToCelsius{
public static void main(String[]args){
convertFToC();
}
/*gets input representing fahrenheit and displays celsius equivalent*/
public static void convertFToC(){
Scanner scan = new Scanner(System.in);
System.out.println("Enter Fahrenheit temperature");
double fahrenheit = scan.nextInt();
System.out.println(fahrenheit + " degrees Fahrenheit is " +
fMethod(celsius) + " degrees Celsius");
}
/* calculates and returns the celsius equivalent */
public static double toCelsius(double fahr){
int BASE = 32;
double CONVERSION_FACTOR = 9.0/ 5.0;
double celsius = ((fahr-BASE)/(CONVERSION_FACTOR));
return celsius;
}
}
我得到以下信息:
Error: celsius cannot be resolved to a variable
我需要使用fMethod 来调用System.out.println 中的toCelsius,但是我不断收到此错误。
【问题讨论】:
-
摄氏度无法解析为变量在哪里?