1、编写程序,实现按 5 度的增量打印出一个从摄氏温度到华氏温度的转换表。转换公式

提一下,有同学是 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;
        }

    }

}

猜你喜欢

转载自blog.csdn.net/c_lanxiaofang/article/details/108571848