I find a very weird situation when writing Java code:
Integer x = myit.next();
if ((int)x % 2 == 0) {
In which myit is an Iterator and x is an Integer. I just want to test whether x is an even number or not. But x % 2 == 0 does not work since eclipse says % not defined on Integer. Then I try to convert x to int by explicitly converting. Again, it warns me that not able to convert in this way.
Any reason why it happened and what is the right way to test if x is even ?
UPDATE: ANYWAY,I test it that the following code works, which means all of you guys are right.
Integer x = 12;
boolean y = ( (x % 2) == 0 );
boolean z = ( (x.intValue() % 2) == 0 );
I think the problem I have before may be the context of the code. It is late night, I would update later if I find why would that thing happen.