java boolean转int,java如何将int转换为boolean
When i convert:
int B=1;
boolean A=B;
It gives error: Incompatible types, which is true
But when I write this code:
int C=0;
boolean A=C==1;
it gives false
while if I change value of C to 1 it gives true.
I don't understand how compiler is doing it.
解決方案
int C=0;
boolean A=C==1;
The compiler first gives C a zero.
Variable : C
Value : 0
Now The Assignment statement,
We know that the assignment statement evaluates the right part first and the gives it to the left.
The right part ==> C == 1
Here, This is an expression which evaluates to true or false. In this case it is false as c is 0.
So the R.H.S is false.
Now this gets assigned to the L.H.S which is A.
A = ( C == 1 ) ==> A = false
As A is a boolean this is a right statement
總結
以上是生活随笔為你收集整理的java boolean转int,java如何将int转换为boolean的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java mybatis cms_jav
- 下一篇: 鼠标手势识别 [Flash]