Home » Interview » Technology

How to identify a given positive decimal number as even/odd without using % or / operator ?

Correct Answer: You may be very good at coding,but if you questioning how on earth you could solve this problemThen here is a solution If you remember the good old days of our primary school then the solution is easy,"division is a matter of iterative subtraction" public class TestEvenOdd { public static void main(String arg[ ]){ int num=6; int result=num; while(result>=2){ result=result-2; } if(result==1){ Systemoutprintln("The number is odd"); }else{ Systemoutprint("The number is even"); } } }

← Previous Question Next Question→

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion