how to tell if a number is even or odd, if statement
Brandi Love
Ranch Hand
Joined: Sep 19, 2003
Posts: 133
posted
0
How can I tell whether or not a given integer is even or odd using java? Also, can I put an if statement within a while loop? [ November 02, 2003: Message edited by: Brandi Love ]
David Crossett
Ranch Hand
Joined: Feb 05, 2003
Posts: 102
posted
0
I hope I'm not just blowing hot air, but this should be easy:
Hope that helps!
David Crossett
-nothing important to say, but learnin' plenty-
[Wayne]: isEven = number % 2 == 0; [Wililam]: That may be legal, but it isn't read-able. It's not? Ummm... how about now? boolean isEven = (number % 2 == 0); [Tom]: isEven = number%2==0?true:false; OK, now that one's pretty funny.
"I'm not back." - Bill Harding, Twister
S Perreault
Ranch Hand
Joined: Oct 29, 2003
Posts: 37
posted
0
Originally posted by William Barnes:
That may be legal, but it isn't read-able.
Actually writing code like this (instead of the first example) is one of the first ways to separate yourself from the newbie programmers. It is as readable as the first example, and much more concise. Perogi.