0
Give me a Java code to check whether the number is even or odd but without using any if else or conditional statement.
use of "?:" is also not allowed
2 Réponses
+ 6
public static void main(String[] args){
System.out.println(isEven(6));
}
private static boolean isEven(int number){
return number % 2 == 0;
}
+ 3
Another solution, same return value:
private static boolean isEven(int number) {
return (number & 1); # logical and ( bits operating, no comparison : mostly efficace if intensive use / no special need of encapsulate in function )
}