Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用多种方法将华氏温度降至摄氏温度_Java - Fatal编程技术网

Java 使用多种方法将华氏温度降至摄氏温度

Java 使用多种方法将华氏温度降至摄氏温度,java,Java,我要做一个程序,把华氏温度转换成摄氏温度,把摄氏温度转换成华氏温度。我还应该使用输入类方法提示输入,我的程序应该有多个方法。到目前为止,我的想法是: public class FahrenheitoCelsius { public static double conversion_fahrenheit_to_celsius() { if(( F >= 0 ) | ( F< 0)) { System

我要做一个程序,把华氏温度转换成摄氏温度,把摄氏温度转换成华氏温度。我还应该使用输入类方法提示输入,我的程序应该有多个方法。到目前为止,我的想法是:

public class FahrenheitoCelsius

{

   public static double conversion_fahrenheit_to_celsius()
      {
          if(( F >= 0 ) | ( F< 0))   
          {
          System.out.println(" The temperature is (Celsius_to_Fahrenheit( y ) ) degrees. " );
          }
          else
          {
          System.out.println(" The temperature is (Fahrenheit_to_Celsius( x ) ) degrees. " );

          }
      }




    public static double Fahrenheit_degrees( double F )
      {
         double F = 32; 
      }
   public static void Celsius_degrees( double C )
     {
         double C = 0;
     }


  public static double Fahrenheit_to_Celsius( double x )
     {
        x = 5/9 * ((Fahrenheit_degrees( F )) - 32);
     }
   public static double  Celsius_to_Fahrenheit( double y)
      {
        y = ( 9/5 * (Celsius_degrees( C ))) + 32; 
      }

}
我如何将这些纳入我的计划?
注意:我不确定到目前为止我提出的程序是否正确;任何反馈都将不胜感激,因为我是Java新手。

您的程序存在一些“错误”,但您需要自己查找并修复这些错误。但是,我将为您提供一个起点:

public static void main(String[] args) {
    String choice = Input.getString("Do you want to convert from Fahrenheit to Celsius (type 'F') or from Celsius to Fahrenheit (type 'C')");
    if ("c".equalsIgnoreCase(choice)){
        //celsius --> fahrenheit code
    } else {
        //fahrenheit --> celsius code
    }
}

我注意到的第一件事是,conversion类中将华氏度转换为摄氏度的方法是不正确的。它总是将打印行中的字符串返回给您。此外,您还需要方法中的输入,因为您使用的方法需要温度输入

所以正确的方法是:

public static double conversion_fahrenheit_to_celsius(double y, double x)
      {
          if(( F >= 0 ) | ( F< 0))   
          {
          System.out.println(" The temperature is " + Celsius_to_Fahrenheit( y ) + " degrees. " );
          }
          else
          {
          System.out.println(" The temperature is " + Fahrenheit_to_Celsius( x ) " degrees. " );

          }
      }
您需要在main方法中使用输入类,如用户ljgw所示


我建议您先看一些教程,然后再看看如何编写Java。一个选择是Newboston-Java初学者编程教程

您需要学习Java编码,这就是代码的错误所在。
public static double conversion_fahrenheit_to_celsius(double y, double x)
      {
          if(( F >= 0 ) | ( F< 0))   
          {
          System.out.println(" The temperature is " + Celsius_to_Fahrenheit( y ) + " degrees. " );
          }
          else
          {
          System.out.println(" The temperature is " + Fahrenheit_to_Celsius( x ) " degrees. " );

          }
      }