java methods a.Write a method called kelvins that takes as input (that is,as argument) a temperature in degreesFahrenheit (of type double) and returns the temperature in degrees Kelvin (also a double).Here is the\x09\x09\x09\x09\x09\x09\x09\x09\x09\x
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/17 06:43:02
java methods a.Write a method called kelvins that takes as input (that is,as argument) a temperature in degreesFahrenheit (of type double) and returns the temperature in degrees Kelvin (also a double).Here is the\x09\x09\x09\x09\x09\x09\x09\x09\x09\x
java methods
a.Write a method called kelvins that takes as input (that is,as argument) a temperature in degrees
Fahrenheit (of type double) and returns the temperature in degrees Kelvin (also a double).Here is the
\x09\x09\x09\x09
\x09\x09\x09
\x09\x09\x09
\x09\x09\x09\x09
\x09\x09\x09\x09\x09
mathematical formula for conversion:
\x09\x09\x09\x09
\x09\x09\x09\x09
\x09\x09\x09\x09\x09
K = 5(F −32)+273.15
9
\x09\x09\x09\x09
\x09\x09\x09
\x09\x09\x09
\x09\x09\x09
\x09\x09\x09\x09
\x09\x09\x09\x09\x09
b.Write another method called temperaturePrinter that takes as input (i.e.as argument) two doubles
and prints the following message to the screen:
\x09\x09\x09\x09\x09
F corresponds to K
where is the temperature in degrees Fahrenheit and is the corresponding temperature
\x09\x09\x09\x09\x09
in degrees Kelvin.
\x09\x09\x09\x09\x09
c.You should test your methods kelvins and temperaturePrinter in the main method by calling them
with 5 different temperatures in degrees Fahrenheit to be converted to Kelvins.Note:you will have to call
both of your methods for each temperature you pick.Also,try to pick numbers that are easy for you to check,
such as 32 F.
java methods a.Write a method called kelvins that takes as input (that is,as argument) a temperature in degreesFahrenheit (of type double) and returns the temperature in degrees Kelvin (also a double).Here is the\x09\x09\x09\x09\x09\x09\x09\x09\x09\x
/*题目大意是写两个函数kelvins(double)和temperaturePrinter(double,double).
kelvins 函数可以把华氏温度F转换成开氏温度K;
temperaturePrinter函数则是打印这两个相对应的温度数值
最后传人32F 测试一下程序.
*/
public class Test {
\x09public static void main(String[] args) {
\x09\x09double f = 32;
\x09\x09double k = kelvins(32);
\x09\x09temperaturePrinter(f, k);
\x09}
\x09public static double kelvins(double f){
\x09\x09double k = 5*(f - 32) + 273.15;
\x09\x09return k;
\x09}
\x09public static void temperaturePrinter(double f,double k){
\x09\x09System.out.println(f+"F corresponds to "+k+"K");
\x09}
}