我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*fileName:P5Q07.java
*Name:Wang Chaoran
* Description:
7 (Conversions between Celsius and Fahrenheit)
Write a class that contains the following two methods:
//Converts from Celsius to Fahrenheit //
public static double celsiusToFahrenheit(double celsius)
//Converts from Fahrenheit to Celsius //
public static double fahrenheitToCelsius(double fahrenheit)
The formula for the conversion is:
fahrenheit = (9.0 / 5) * celsius + 32
Write a test program that invokes these methods to display the following tables:
Celsius Fahrenheit Fahrenheit Celsius
40.0 105.0 120.0 48.89
39.0 102.2 110.0 43.33
...
32.0 89.6 40.0 5.44
31.0 87.8 30.0 -1.11
*/
import java.util.Scanner;
public class P5Q07{
public static void main(String[] args){
System.out.println("Celsius Fahrenheit Fahrenheit Celsius");
for(double i = 40.0;i >= 31.0;i -= 1.0){
System.out.print(" "+i+" ");
System.out.printf("%5.1f",celsiusToFahrenheit(i));
System.out.print(" "+(i-28)*10+" ");
if((i-28)*10<100)
System.out.print(" ");
System.out.printf("%5.2f",fahrenheitToCelsius((i-28)*10));
System.out.println();
}
}
public static double celsiusToFahrenheit(double celsius){
return (9.0 / 5) * celsius + 32;
}
public static double fahrenheitToCelsius(double fahrenheit){
return (fahrenheit - 32) * 5 / 9.0;
}
}
//fahrenheit = 120; (in the loop )fahrenheit -= 10; printf("%3d%4d%4d%8d",kjsdf,ksdf,ksdf,jksdf);or use while(celsius >=31.o){ celsius--;}
导入论坛查看(43)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing