Frnds, My questions is "how come to know whether the number is even or odd without using %,/,bitwise operator".
vivekH
0
Light Poster
Recommended Answers
Jump to Postif any number modulus 2 is zero then it's even otherwise it's an odd number so your condition would be
if (Num%2==0) sop("EVEN");
Jump to PostI guess you didn't read the bit about not using %
Jump to PostCan you use shift operators?
Jump to Postoops sorry.
without using %
Jump to PostThe (definitive) Java Language Spec describes 'bitwize" operators in section 15.22, but shift operators in section 5.19, which to me confirms that shift operators are not "bitwize" operators, so are not forbidden for this exercise.
So: shift your number one bit right, then back 1 bit left again, and if …
All 17 Replies
oussama_1
39
Posting Whiz in Training
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
oussama_1
39
Posting Whiz in Training
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
vivekH
0
Light Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
vivekH
0
Light Poster
cgeier
187
Junior Poster
Tarek_2
26
Light Poster
cgeier
187
Junior Poster
TylerD75
0
DaniWeb Newbie
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
cgeier
187
Junior Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Slavi
94
Master Poster
Featured Poster
vivekH
0
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.