Pergunta de entrevista da empresa eBay

What way can you tell if an integer is odd or even?

Respostas da entrevista

Sigiloso

9 de mai. de 2011

public class CheckEvenOrOdd { public static int EvenOrOdd2(int num) { return (num&1); } public static void main(String[] args){ System.out.println("Enter an integer to check for Even/Odd: "); Scanner myscan = new Scanner(System.in); int inputNo = myscan.nextInt(); System.out.println("The entered number was: "+(CheckEvenOrOdd.EvenOrOdd2(inputNo)==0?"Even":"Odd")); } }

1

Sigiloso

5 de nov. de 2015

Use Bitwise &

Sigiloso

4 de fev. de 2011

I said use the mod because the remainder will tell you. He wanted bit operators (AND, OR, XOR). Really ???