练习1: 使用公式C=(5/9)(F-32)打印下列华氏温度与摄氏温度对照表。

来源:互联网 发布:linux图标为什么是企鹅 编辑:程序博客网 时间:2024/05/21 09:21

练习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 F_C{
public static void  main(String args[]){
for(int i=0;i<=300;i+=20){
System.out.printf("%d\t%.1f\n",i,(i-32)*5/9.0);
}
}
}


public class F_C_NI{
public static void  main(String args[]){
for(int i=300;i>=0;i-=20){
System.out.printf("%d\t%.1f\n",i,(i-32)*5/9.0);
}
}
}


分析:通过练习,我认为应该学会使用for循环语句,学会输出表达式

阅读全文
0 0