练习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 Work1{
	public static void main(String args[]){

		//#################################################################
		System.out.println("温度输出\n");
		
		System.out.println("F \t C ");
		int temp;
		for(int i=0;i<=300;i+=20){	
			temp=(int)(((5.0/9.0)*(((double)i)-32.0))*10);
			System.out.println(i+"\t"+((double)temp)/10.0   );
		}
		System.out.println("温度输出-结束\n");
		//#################################################################	
		//#################################################################
		System.out.println("温度倒序输出\n");
		
		System.out.println("F \t C ");
		//int temp;
		for(int i=300;i>=0;i-=20){	
			temp=(int)(((5.0/9.0)*(((double)i)-32.0))*10);
			System.out.println(i+"\t"+((double)temp)/10.0   );
		}
		System.out.println("温度倒序输出-结束\n");
		//#################################################################	

	}
} 

练习1:打印华氏温度与摄氏温度对照表_第1张图片

你可能感兴趣的:(作业。。。。。。。。。。。。。)