• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

What is the definition of...

Well, I'm trying to get this program to tell the difference between even and odd numbers... (e.g. the integer 4; even? true; odd? false). Things of that nature.
 
You'd probably have to use the 'mod' function and use 2. If the number is even, the value will be 0. If it's odd, it will be nonzero. You can then use that for your logic statements.
 
can you use bitwise operators like &

because if a number is even it's lowest bit in binary will be 0, else 1 so you can "and" the number with 1 to check the loest bit

i don't think logical operators can do it
 
I can use &&, !, ==, ||.
The language is Java, say I have an int i, i being an integer, I must give characteristics of it such that I get even? odd? positive? zero? negative?
The last 3 are obvious to me, but the others I can't seem to get in code. In English, fine, but using operators, I'm lost.

For example, if I'm giving the characteristic for a negative number, then: i < 0; for positive: i > 0; for zero: i == 0
Then prompting a user to input an integer, 7, for example, then:

even? false; odd? true; positive? true; zero? false; negative? false
 
Back
Top