【发布时间】:2016-03-17 19:29:03
【问题描述】:
我正在使用循环为 0 到 20 之间的华氏温度制作华氏到摄氏度的转换表,但我无法让我的方法返回正确的摄氏度。到目前为止,程序将输出适当的华氏温度到 20 度,但它会为每个华氏度输出输出 0* 华氏度的摄氏度转换。如何让我的方法在方法方程中使用不断增加的华氏温度变量? 到目前为止,这是我的代码:
import java.text.DecimalFormat;
public class CelsiusTemperatureTable
{
public static void main(String[] args)
{
DecimalFormat df = new DecimalFormat("#.0");
double farenheit = 0;
double celsius = celsius(farenheit);
while (farenheit <= 20)
{
System.out.println( farenheit + "\t\t" + df.format(celsius));
farenheit++;
}
}
public static double celsius(double farenheit)
{
double temperature = farenheit - 32;
double temperature1 = temperature * .556;
return temperature1;
}
}
【问题讨论】: