这是我现在的代码: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;
}
此外,为什么要对变量使用大写字母,按照惯例,变量名应该以小写字母开头,对象名则以大写字母开头。