上机练习3
3、华氏温度和摄氏温度互相转换,从华氏度变成摄氏度你只要减去32,乘以5再除以9就行了,将摄氏度转成华氏度,直接乘以9,除以5,再加上32即行。[选做题],
public class t3 { public static void main(String[] args) { // TODO Auto-generated method stub float a = 36.2f; float b = 100.0f; float aTob = (b - 32) * 5 / 9; float bToa = a * 9 / 5 + 32; System.out.println("摄氏转华氏=" + aTob); System.out.println("华氏转摄氏=" + bToa); } }