G
Guest
Hi,
I have a doubt.Why doesn't the following loop work?
Logically,the if statement should have been satisfied atleast once.
class Test {
public static void main(String[] args) {
for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) {
if (b == 0x90)
System.out.print("Printed");
}//loop-ends
}
}
It works with:
if(b==(byte)0x90)
But,
0x90 = 00....0000 1001 0000 +144
(byte)0x90 = 1001 0000 -0x70
-0x70 is well within the byte range.Then what makes it unequal to all
byte values?
Thanks in advance.
I have a doubt.Why doesn't the following loop work?
Logically,the if statement should have been satisfied atleast once.
class Test {
public static void main(String[] args) {
for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) {
if (b == 0x90)
System.out.print("Printed");
}//loop-ends
}
}
It works with:
if(b==(byte)0x90)
But,
0x90 = 00....0000 1001 0000 +144
(byte)0x90 = 1001 0000 -0x70
-0x70 is well within the byte range.Then what makes it unequal to all
byte values?
Thanks in advance.