gpt4 book ai didi

java - 不兼容的类型 : possible lossy conversion from int to byte

转载 作者:行者123 更新时间:2023-12-01 18:06:32 25 4
gpt4 key购买 nike

我尝试为学校编写一些代码,但我不断收到此编译错误:

error: incompatible types: possible lossy conversion from int to byte

A = (byte)C / (byte)B;

System.out.println("Aufgabe 4");

byte A=11; int B, C;
B = A + A;
C = B * (int)1.0;
A = (byte)C / (byte)B;

最佳答案

原因是您没有将除法运算的整数结果转换为字节:

A = (byte) C / (byte)B; // you cast C to byte, cast B to byte and then make division

相反,仅转换结果

A = (byte) (C / B);  // this is casting result to byte

关于java - 不兼容的类型 : possible lossy conversion from int to byte,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36040537/

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