【发布时间】:2021-02-08 00:54:01
【问题描述】:
所以我已经尝试了所有方法,但由于某种原因,我的 JAVA 程序根本无法编译。我认为我使用的数学方法的数据类型有问题。这是代码
public static int getOuthaul(int manganous, int nakir) {
if (manganous > nakir) {
double tmp = Math.sqrt(Math.abs(manganous - nakir));
return Math.round(tmp);
}
}
我非常需要一个回答的人。这意味着很多! 谢谢
这是全班:
public class Vijao {
public static int getOuthaul(int manganous, int nakir) {
if (manganous > nakir) {
double tmp = Math.sqrt(Math.abs(manganous - nakir));
float mpp = (float)tmp;
return Math.round(tmp);
} else {
return Math.abs(manganous - nakir);
}
}
public static int getUnhulled(int toilfully, int corse, int outwrench) {
int wilbur = corse + 16 * toilfully;
if (wilbur * wilbur > outwrench)
return wilbur;
else {
return wilbur * (-1);
}
}
这就是错误
错误:不兼容的类型:从 long 到 int 的可能有损转换 返回 Math.round(tmp); ^
【问题讨论】:
-
贴出所有课程代码
-
当这是整个方法时,您需要一个右括号并在 if 之后返回一个 .... 如果不执行 if 时该方法应该返回什么
-
请发布您看到的确切编译错误。
-
请与我们分享您遇到的错误。第一个问题是您要返回
Math.round的结果,这可能是double但您的方法希望您返回int -
请不要对我们大喊大叫!
标签: java class math types return