for (int x = 0; x < 100; x++) { boolean notZero = x != 0; int previous = x - 1; int and = x & previous; boolean isMultipleOfTwo = notZero && (and == 0); System.out.println(String.format("%d = %s", x, isMultipleOfTwo)); }