【发布时间】:2017-01-26 20:37:28
【问题描述】:
在我的代码中需要一些东西。我已经连续看了 8 个小时,无法弄清楚。我需要用户输入介于 -459 和 212 之间。如果它是超出范围的整数,它将打印 line 以重新输入,然后继续进行转换。现在它没有做任何一个,只是通过代码。我应该使用布尔值还是 if when?不知道。
第二个问题是当华氏温度和摄氏温度在转换后打印出来时,我需要它们再列出 20 行,每个温度加 10。这是算数吗?请需要主要帮助!
到目前为止我所拥有的:
import java.text.DecimalFormat;
import java.util.Scanner;
public class Temperatures {
public static void main(String[] args) {
double Fahrenheit;
double Celsius;
Scanner scan = new Scanner(System.in);
System.out.print("Enter temperature in Fahrenheit: ");
Fahrenheit = scan.nextInt();
if(Fahrenheit >= -459 && Fahrenheit <= 212)
System.out.println("Please enter a number between -459 and 212 degrees:");
Fahrenheit = scan.nextInt();
Celsius = ((Fahrenheit -32)*5)/9;
DecimalFormat fmt = new DecimalFormat("#.##");
System.out.print("Fahrenheit: " + Fahrenheit + " Celsius: " + fmt.format(Celsius));
}
}
【问题讨论】:
-
现在我的华氏温度和摄氏温度变量还没有初始化。
标签: java loops boolean conditional