• + 1 comment

    Replace your code with this line:

    System.out.println((((k - 1) | k) > n && k % 2 == 0) ? k - 2 : k - 1);