提一下,有同学是 double f = 9.0/5*C + 32; 的,这样是不可以的,
可能在想程序按顺序执行,可是Java不,Java会给你算成double f = 9.0/(5*C) + 32; ,
如果一定要把C放后面,除非你 double f = (9.0/5)*C + 32;
package com.temp;
/**
* @Author lanxiaofang
* @email [email protected]
* @date 2020/09/14 08:10
*/
public class CToF {
public static void main(String[] args) {
int c1 = 0;
for(int i = 1; i < 10; i++){
double f = 9.0*c1/5+32;
System.out.println(c1 +"C --> "+ f +"F");
c1+=5;
}
}
}