[英]Why is my program only outputting my println statements and not my print f ones?
我需要我的程序以某種格式打印出某些標題下的值表,以便生成溫度轉換圖表。 當我運行我的程序時,它只給我程序的頭輸出,而不是我的 for 循環。 代碼:
public static double fToC(double f){
double c1 = (( f - 32 ) * 5 / 9 );
return c1;
}
public static double cToF(double c){
double f1 = (( c * 9 / 5 ) + 32);
return f1;
}
public static void main(String args[]) {
double f = -40;
double c = -40;
double f1 = cToF(f);
double c1 = fToC(c);
System.out.println(" Temperature Conversion Tables");
System.out.println("");
System.out.println(" Temperature | Temperature");
System.out.println(" (degrees) | (degrees)");
System.out.println(" F C | F C");
for (f = -40; f == 455; f+=5) {
System.out.printf("%.3d", "%5.3d", "%3s", f, c1, "|");
}
for (c = -40; c == 455; c+=5) {
System.out.printf("%4.3d", "%5.3d%n", c, f1);
}
}
您提供的條件不適用於 (f = -40; f == 455 ; f+=5)
這永遠不會是真的,你必須提供小於或大於 then (f = -40; f <= 455 ; f+=5) (f = -40; f >= 455 ; f-=5) 的條件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.