java第一课

来源:互联网 发布:苹果越狱会清除数据吗 编辑:程序博客网 时间:2024/05/16 01:46

练习1:
使用公式C=(5/9)(F-32)打印下列华氏温度与摄氏温度对照表。
0      -17
20     -6
40     4
60     15
80     26
100    37
120    48
140    60
160    71
180    82
200    93
220    104
240    115
260    126
280    137
300    148
思考:
加入制表符使数据输出更整齐;
让摄氏温度保留一位小数。
修改温度转换程序,要求以逆序(从300度到0度的顺序)打印温度转换表。



public class temperature{public static void main(String[] args){System.out.println("顺序输出:");System.out.println("摄氏度"+"/t"+"华氏度");for( int c = 0;c <=300; c+=20){System.out.printf("%d\t%.1f\n",c,(float)(5.0/9)*(c-32));}}}


原创粉丝点击