> General Computer Programming (Java) problem solving help???

General Computer Programming (Java) problem solving help???

Posted at: 2014-12-18 
Drop the decimal. Use the mod operator - % 2. If the current number is even, the result of the mod will be 0. If it isn't, subtract 1 and test again. This time the result of the mod operation should be 0, meaning that the number is even.

So, if x=4.2 then the answer is 4, but if x=4 then the answer is 2?

Here is Python code:

even = 2 * (int (x) /2)

if x==even: even -=2