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

使用公式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度的顺序)打印温度转换表。

//  这是保留一位小数,最大的难点就是num的强制类型转换

import java.util.Scanner;

public class Lesson1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		/*Scanner input=new Scanner(System.in);	
		int f=input.nextInt();*/
	     for(int i=0;i<=300;i+=20){
	    	 double  num=  (((double)5/9)*(i-32));
	    	 String  temp=String.format("%.1f", num);
	    	 System.out.println(i+"	"+temp);
	     }
		
	}

}


发布了143 篇原创文章 · 获赞 1 · 访问量 1584

猜你喜欢

转载自blog.csdn.net/zhupengqq1/article/details/104087296