这是一个问题。对于开尔文和华氏温度之间的转换,使用转换方法在开尔文和摄氏度之间以及摄氏和华氏之间进行转换。修改main()方法以包含添加的新方法的测试用例。
package projectTwo;
public class projectTwo {
public static double f2c(double fahrenheit)
{
return 5.0 / 9.0 * (fahrenheit - 32.0);
}
public static double c2f(double celsius)
{
return 9.0 / 5.0 * celsius + 32.0;
}
public static double k2c(double kelvin)
{
return 5.0 / 9.0
public static void main(String[] args)
{
System.out.printf("%.2f F => %.2f C%n", 32.0, f2c(32.0));
System.out.printf("%.2f F => %.2f C%n", 212.0, f2c(212.0));
System.out.printf("%.2f C => %.2f F%n", 0.0, c2f(0.0));
System.out.printf("%.2f C => %.2f F%n", 100.0, c2f(100.0));
}
}
这就是我遇到的问题。
答案 0 :(得分:0)
你有错误的{}
夫妻。 }
方法的末尾缺少一个结尾public static double k2c(double kelvin)
。这可能是一个错字,你的代码中没有语法错误,但无论如何请修复它。
另一个错误是打印新行时。您必须使用\n
(不是%n
,因为您已经使用过)。所以你的代码应该是这样的:
System.out.printf("%.2f F => %.2f C\n", 32.0, f2c(32.0));
System.out.printf("%.2f F => %.2f C\n", 212.0, f2c(212.0));
System.out.printf("%.2f C => %.2f F\n", 0.0, c2f(0.0));
System.out.printf("%.2f C => %.2f F\n", 100.0, c2f(100.0));
答案 1 :(得分:0)
package gradedhomeworkproject; 公共类GradedHomeworkProject {
public static double f2c(double fahrenheit)
{
return 5.0 / 9.0 * (fahrenheit - 32.0);
}
public static double c2f(double celsius)
{
return 9.0 / 5.0 * celsius + 32.0;
}
public static double k2c(double kelvin)
{
return 5.0 / 9.0 * kelvin;
}
public static double c2k(double celsiusx)
{
return (9.0 / 5.0 - 273.15) - 1.8;
}
public static void main(String[] args)
{
System.out.printf("%.2f F => %.2f C%n", 32.0, f2c(32.0));
System.out.printf("%.2f F => %.2f C%n", 212.0, f2c(212.0));
System.out.printf("%.2f C => %.2f F%n", 0.0, c2f(0.0));
System.out.printf("%.2f C => %.2f F%n", 100.0, c2f(100.0));
System.out.printf("%.2f K => %.2f C%n", 273.16, k2c(0.0));
System.out.printf("%.2f C => %.2f K%n", 0.0, c2k(-273.16));
}
} "这就是我现在所拥有的。"
答案 2 :(得分:0)
包morejava; 公共类MoreJava { public static double f2c(double fahrenheit)
{
return 5.0 / 9.0 * (fahrenheit - 32.0);
}
public static double c2f(double celsius)
{
return 9.0 / 5.0 * celsius + 32.0;
}
public static double c2k(double celsiusX)
{
return celsiusX + 273.15;
}
public static double k2c(double kelvin)
{
return kelvin - 273.15;
}
public static double f2k(double fahrenheitX)
{
return (fahrenheitX + 459.67) * 5.0 / 9.0;
}
public static double k2f(double kelvin)
{
return kelvin * 9.0 / 5.0 - 459.67;
}
public static void main(String[] args)
{
System.out.printf("%.2f F => %.2f C%n", 32.0, f2c(32.0));
System.out.printf("%.2f F => %.2f C%n", 212.0, f2c(212.0));
System.out.printf("%.2f C => %.2f F%n", 0.0, c2f(0.0));
System.out.printf("%.2f C => %.2f F%n", 100.0, c2f(100.0));
System.out.printf("%.2f C => %.2f K%n", 0.0, c2k(0.0));
System.out.printf("%.2f C => %.2f K%n", 100.0, c2k(100.0));
System.out.printf("%.2f K => %.2f C%n", 273.15, k2c(273.15));
System.out.printf("%.2f K => %.2f C%n", 373.15, k2c(373.15));
System.out.printf("%.2f F => %.2f K%n", 32.0, f2k(32.0));
System.out.printf("%.2f F => %.2f K%n", 212.0, f2k(212.0));
System.out.printf("%.2f K => %.2f F%n", 273.15, k2f(273.15));
System.out.printf("%.2f K => %.2f F%n", 373.15, k2f(373.15));
}
}
我很自豪地说我弄清楚了!
答案 3 :(得分:-1)
您必须关闭方法public static double k2c(double kelvin)
在返回后添加}
和半冒号...
package projectTwo;
public class projectTwo {
public static double f2c(double fahrenheit)
{
return 5.0 / 9.0 * (fahrenheit - 32.0);
}
public static double c2f(double celsius)
{
return 9.0 / 5.0 * celsius + 32.0;
}
public static double k2c(double kelvin)
{
return 5.0 / 9.0;
}
public static void main(String[] args)
{
System.out.printf("%.2f F => %.2f C%n", 32.0, f2c(32.0));
System.out.printf("%.2f F => %.2f C%n", 212.0, f2c(212.0));
System.out.printf("%.2f C => %.2f F%n", 0.0, c2f(0.0));
System.out.printf("%.2f C => %.2f F%n", 100.0, c2f(100.0));
}
}