#Modern java programming book: confused on how to solve a challenge

1 messages · Page 1 of 1 (latest)

sonic walrus
#

what is it asking me to do exactly?

modest kiteBOT
#

<@&987246399047479336> please have a look, thanks.

north peak
#

where it says < CODE HERE >

sonic walrus
#

okay

north peak
#

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

#

where u learned about the % operator

#

🙂

sonic walrus
#

because the modulo operator is for finding reminders right?

north peak
sonic walrus
#

okay

north peak
#

how do u determine in ur brain whether a number is even or odd

#

lets say the number 173

#

even or odd?

#

and why

sonic walrus
#

ohhhh

sonic walrus
north peak
#

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

sonic walrus
#

ah so its an even or odd kind of question, i was confused, thought it was asking me to use the == operator

north peak
#

yeah, ull have to use that

#

in combination with making the remainder

sonic walrus
#

okay so lemme try off the bat

north peak
#

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

sonic walrus
#

boolean xIsEven = x % 2 == 0;

north peak
#

awesome!

#

and challenge 3 is essentially done

#

great

sonic walrus
#

thank you very much for the help!