这是我现在的代码:http://ideone.com/PfXNQc
import java.util.Scanner;
public class Temperature
{
public static double convertFtoC(double F)
{
return (F-32)*5/9;
}
public static void main(String[] args)
{
double F; //Stores Farenheit
double C; //Stores Celsius
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a temperature in Fahrenheit: "); //Enter in Farenheit
F = keyboard.nextDouble(); //Stores Farenheit
System.out.println("The temperature in Celsius is: " + convertFtoC(F)); //Displays Celsius (call convertFtoC(F) where celcuis conversion needed)
F = 0;
System.out.println("Fahrenheit\t Celsius");
while (F <= 100)
{
// Display the F and C in increments of 10.
System.out.println(F + "\t\t" + convertFtoC(F));
// Increment for the next day.
F++;
}
}
}
我希望转换循环以 10 而不是 1 的增量上升。
现在它正在输出这个:
但我希望它是
0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
最佳答案
如果你这样写呢
while (F <= 90) //Last number before 100 is 90
{
// Display the F and C in increments of 10.
System.out.println(F + "\t\t" + convertFtoC(F));
// Increment for the next day.
F=F+10;
}
另外,为什么你对变量使用大写字母,按照惯例你应该以小写字母开头变量名,对象名以大写字母开头。
关于java - 如何将循环递增 10 而不是 1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32835243/