尝试使用方法进行转换,但是运行时它没有执行任何操作,我做错了什么?
java
...
Scanner input = new Scanner(System.in);
int selection = 0;
switch selection {
case 1:
int k = input.nextInt();
System.out.println(celsius(k));
break;
case 2:
int j = input.nextInt();
System.out.println(fahrenheit(j));
break;
}
...
public static double fahrenheit(double celsius) {
double fahrenheit;
fahrenheit = 9 / 5 * (celsius + 32);
return fahrenheit;
}
public static double celsius(double fahrenheit) {
double celsius;
celsius = 5 / 9 * (fahrenheit - 32);
return celsius;
}
...
plpStyleData.setStatus(ActionResponseStatus.SUCCESS);
return plpStyleData;
}
最佳答案
因为 selection = 0
所以开关不会进入 case 1:
和 case 2:
部分。您可能需要将其设置为 input.nextInt()
,以便它首先要求输入。
关于java - 使用方法在摄氏度和华氏度之间转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60078755/