1. Write a program to print out a conversion table from Celsius to Fahrenheit in increments of 5 degrees. Conversion formula

Just to mention, some students have double f = 9.0/5*C + 32;, this is not possible.

You may be thinking that the program will be executed in order, but Java does not. Java will give you double f = 9.0/(5*C) + 32;,

If you must put C behind, unless you  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;
        }

    }

}

Guess you like

Origin blog.csdn.net/c_lanxiaofang/article/details/108571848
Recommended