How can I check if something is an even number?

I need to make something so that if int x is even then boolean y will be true. But I cannot find how to see if something is even? I tried something likeif (x / 2 ==int)

lol but that does not work. So what is the statement?

[304 byte] By [punchouta] at [2007-10-1 0:52:22]
# 1
Check the modulus operator - %.if(i%2 == 0)
alhay99a at 2007-7-8 1:07:41 > top of Java-index,Security,Event Handling...
# 2
mod (%) is the operator you are looking for. it gives the remainder after divisioni.e:boolean iseven = (number % 2) == 0;
silk.ma at 2007-7-8 1:07:41 > top of Java-index,Security,Event Handling...
# 3
Another way is to test if the least significant bit is set or not.if (i & 1 == 0) {//It's even.}/Kaj
kajbja at 2007-7-8 1:07:41 > top of Java-index,Security,Event Handling...
# 4
> if (i & 1 == 0) {This trick actually works for any power of 2 .. i.e.n % powerOf2 == n & (powerOf2 - 1);
silk.ma at 2007-7-8 1:07:41 > top of Java-index,Security,Event Handling...
# 5
> > if (i & 1 == 0) {> > This trick actually works for any power of 2 .. i.e.> > n % powerOf2 == n & (powerOf2 - 1);I'm sorry, that tests for even-ness?n & -n == n// true if n is a power of two
Adeodatusa at 2007-7-8 1:07:41 > top of Java-index,Security,Event Handling...
# 6
> > n % powerOf2 == n & (powerOf2 - 1);> > I'm sorry, that tests for even-ness?no, it is a statement by itself (i.e. n & powerOf2 is equiv to n & (powerOf2 - 1))
silk.ma at 2007-7-8 1:07:41 > top of Java-index,Security,Event Handling...
# 7
alright thanks guysI forgot about the % just because we never used it in 'real' math class so I never remember it.
punchouta at 2007-7-8 1:07:41 > top of Java-index,Security,Event Handling...
# 8

> alright thanks guys

>

> I forgot about the % just because we never used it in

> 'real' math class so I never remember it.

I much prefer imaginary math. Even still, I wish they would allow the mod operator in class and put in on calculators, it can really help sometimes...

Adeodatusa at 2007-7-8 1:07:41 > top of Java-index,Security,Event Handling...
# 9
Did none of you have remainders from calculating a division? :)
Peter-Lawreya at 2007-7-8 1:07:41 > top of Java-index,Security,Event Handling...
# 10
> Did none of you have remainders from calculating a> division? :)I know there are work-arounds for it, but a persent-sign is so much more concise.
Adeodatusa at 2007-7-8 1:07:41 > top of Java-index,Security,Event Handling...