Monday, August 07, 2006

Is this methods fool proof?

Does this method make a valid check for even numbers?

public static boolean isEven(int i) {
return i % 2 == 1;


Arvind said...

so what about the case when "i" is negative, the result of "i%2" will be negative, that means it doesn't consider the case of negative values. Solution can be, "abs(i%2) == 1". This might solve it. Other than this I couldn't find any other problem.

Arvind said...

Or make "i" an unsigned integer :)