`java(0%2!= 0)== false`

我一直坚持的部分是
布尔值(0%2!= 0)
== false.我的意思是如果2进入0,0次然后余数将是2,而2不等于0.所以它应该是真的.然而,当我把boolean放在我的 java程序中时,它将它视为false.谁知道为什么?

我可以解决的唯一合乎逻辑的答案是,整数可能会进入0且无限次,所以被认为是假的,有人吗?

解决方法

有两个步骤:

> 0%2评估为0.
> 0!= 0的计算结果为false.

要详细说明第一步,JLS defines%运算符如下:

The binary % operator is said to yield the remainder of its operands from an implied division; the left-hand operand is the dividend and the right-hand operand is the divisor.

将0除以2的余数为0而不是2,正如您所想的那样.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...