下面的代码结果“39 44”作为输出。我在某处读到,类型转换在这里使用模数。我知道基本如何计算模数,例如 10%3 = 1,但我仍然不明白这里是如何计算的。
class conversion {
public static void main(String args[])
{
double a = 295.04;
int b = 300;
byte c = (byte) a;
byte d = (byte) b;
System.out.println(c + " " + d);
}
}
最佳答案
字节范围是-128到127。 所以字节(128)将是-128。 byte(129) 将为 -127。 byte(256) 将为 0。 字节(257)=1 字节(295)=39。 字节(295.04)=字节(295)=39。
关于java - Java 中的转换如何使用模数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43424184/