以下代码结果“ 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。
    因此byte(128)将为-128。
    字节(129)将为-127。
    字节(256)将为0。
    字节(257)= 1
    字节(295)= 39。
    字节(295.04)=字节(295)= 39。

关于java - 如何使用模数在Java中进行转换,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43424184/

10-12 17:40
查看更多