#Modern java programming book: confused on how to solve a challenge
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
lets start with the first one
where it says < CODE HERE >
okay
ur supposed to put code there so that the IO.println(xIsEven) would print out whether that x is even or not
this challenge is about chapter 7.6
Book teaching how to write modern and effective Java.
where u learned about the % operator
🙂
wait do i compare x to y and stuff or
because the modulo operator is for finding reminders right?
lets step back and think about it without code first
okay
how do u determine in ur brain whether a number is even or odd
lets say the number 173
even or odd?
and why
ohhhh
odd because it leaves a remainder when devided by 2
yeeeeah!
or in other words:
u determine that by it being divisble by 2. what does divisible mean? that if u divide it, the remainder is 0
so, now u just have to translate that into code
ah so its an even or odd kind of question, i was confused, thought it was asking me to use the == operator
okay so lemme try off the bat
a number is even if its remainder (divided by 2) is 0
"is 0" means == 0
now u need the part to the left of the == 0
which is "the remainder (after dividing by 2)"
so translate that into code, put it together and u have it

boolean xIsEven = x % 2 == 0;
thank you very much for the help!