【发布时间】:2017-08-27 02:34:47
【问题描述】:
代码应该输出华氏温度和摄氏温度的表格
public static void main(String[] args) {
System.out.println("Fahrenheit\tCelsius");
System.out.println("=======================");
for(int temp = -45; temp <= 120; temp += 5) //for(int i = 0; i <= 100; i+= 10)
{
System.out.printf("%5d |", temp);
double sum = (temp + (9.0/5.0)) * 32;
System.out.printf("%5d", (int)sum );
System.out.printl
n();
【问题讨论】:
-
一个主要问题:不要在 while 循环中不断地重新创建 Scanner。您将 Scanner 基于 System.in,并且您不希望它在程序完全完成并且不再需要此输入之前结束。因此,只在 before 您的 while 循环中设置一次 Scanner。
-
我有似曾相识的漏洞吗?前几天我不是几乎同样的问题吗?是不是碰巧被关闭和删除了,现在你再试一次?
-
感谢您的回答。我确实有这种倾向。我看看能不能修改。 @气垫船。
-
我不知道你在说什么,我只是想学习/理解。如果你不想帮忙,那很好。 @鬼猫
标签: java if-statement while-loop do-while