public static void temperatures (int minTemp, int maxTemp, int increment ){
int F = 0; // Fahrenheit
double C, K; //Celsius, Kelvin
for ( minTemp = 0; minTemp <= maxTemp ; minTemp++){
C = ( F - 32.0) * 5.0/9.0;
K = C + 273.15;
increment++;
System.out.println( temperatures );
}
}//end temperatures
//This is what is supposed to print
//Fahrenheit Celsius Kelvin
//----- | ------- | ------
// 10 | -12.22 | 260.93
它还循环 10 次,所以华氏温度变为 10 - 100 等,然后停止,所以我认为 for 循环需要循环 10 次,而不是它的实际情况,但我不太确定,因为我无法打印任何内容
最佳答案
您可以按如下方式进行:
public class BinarySearchDemo {
public static void main(String[] args) {
temperatures(0, 100, 10);
}
public static void temperatures(int minTemp, int maxTemp, int increment) {
double c, k; // Celsius, Kelvin
for (int f =minTemp;f <= maxTemp; f+=increment) {
c = (f - 32.0) * 5.0 / 9.0;
k = c + 273.15;
System.out.printf("%3d|%8.2f|%8.2f\n",f,c,k);
}
}// end temperatures
}
输出:
0| -17.78| 255.37
10| -12.22| 260.93
20| -6.67| 266.48
30| -1.11| 272.04
40| 4.44| 277.59
50| 10.00| 283.15
60| 15.56| 288.71
70| 21.11| 294.26
80| 26.67| 299.82
90| 32.22| 305.37
100| 37.78| 310.93
关于java - 我试图用这种方法正确打印温度,但我卡住了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58531532/