5 ms·
How to find Even or Odd number without Modulus Operator
- charleslmunger 14y agoDear ${DEITY}, this makes all java programmers look bad. Really all it should say is public static boolean isOdd(int i) { return i & 1 == 1; }
- javinpaul 14y agoThis looks really nice, better than isEven() version. public static boolean isOdd(int i) { return i & 1 == 1; }
- ryankey721 14y agoAre problems like these actually asked during job interviews? I don't mean that this isn't a good topic, just that I always imagined that interview questions would be harder to solve and that they wouldn't ask for contrived solutions (solutions that aren't obvious and could lead to bugs for new coders, while not being better in many other ways).
- javinpaul 14y agoHi Ryankey721, yes, it does get asked. Interviews are funny, some time you get theoretical non relevant question, some time easy one like this, and very rarely relevant coding exercise.