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

来源:互联网 发布:软件开发企业收入确认 编辑:程序博客网 时间:2024/05/17 23:53

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 tem {


public static void main(String[] args) {
// TODO Auto-generated method stub
for(int i=0;i<=300;i=i+20)
{
float c=(float) ((5.0/9)*(i-32));
System.out.print(i+"\t");
System.out.printf("%3.1f",c);
System.out.println();
}


for(int i=300;i>=0;i=i-20)
{
float c=(float) ((5.0/9)*(i-32));
System.out.print(i+"\t");
System.out.printf("%3.1f",c);
System.out.println();
}
}


}








阅读全文
0 0
原创粉丝点击