gpt4 book ai didi

java错误不兼容的类型需要int找到double

转载 作者:行者123 更新时间:2023-12-01 10:40:52 25 4
gpt4 key购买 nike

我在 intellij idea 中收到以下错误。

incompatible types. required int found double

我是java新手,不知道这个错误是什么。

public class Temperature {
public int calculateF(int cs){
int f = cs * 9/5 + 32;
return f;
}
public int calculateC(int f){
int c = (f-32/1.8000);
return(c);
}
}

最佳答案

除以1.8 得到double。如果你想要一个int,你需要进行强制转换或舍入。比如,

public int calculateC(int f) {
return Math.round(f - 32 / 1.8f);
}

关于java错误不兼容的类型需要int找到double,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34408849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com