错误:摄氏无法解析为变量

Ron*_*ish 1 java variables methods

使用以下代码获取错误:

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;
  }
}
Run Code Online (Sandbox Code Playgroud)

我得到以下内容:

Error: celsius cannot be resolved to a variable
Run Code Online (Sandbox Code Playgroud)

我需要用来fMethod调用toCelsius,System.out.println但是我不断收到这个错误.

Jon*_*eet 7

您根本没有显示fMethod,但看起来您只是想要:

System.out.println(fahrenheit + " degrees Fahrenheit is " + toCelsius(fahrenheit)
                   + " degrees Celsius");
Run Code Online (Sandbox Code Playgroud)

您不能使用celsiusin,main因为它是方法中的局部变量toCelsius.相反,您需要调用该方法并使用返回值.