@@ -0,0 +1,623 @@
+package chapter_5;%0A%0Apublic class NextNumber %7B%0A%0A  public int getNext(int n) %7B%0A    int onesCount = countOnes(n);%0A    for (int i = n + 1; i %3C= Integer.MAX_VALUE; i++) %7B%0A      if (countOnes(i) == onesCount) %7B%0A        return i;%0A      %7D%0A    %7D%0A    return n;%0A  %7D%0A%0A  public int getPrevious(int n) %7B%0A    int onesCount = countOnes(n);%0A    for (int i = n - 1; i %3E= 0; i--) %7B%0A      if (countOnes(i) == onesCount) %7B%0A        return i;%0A      %7D%0A    %7D%0A    return n;%0A  %7D%0A%0A  private int countOnes(int n) %7B%0A    int numOnes = 0;%0A    for (int i = 0; i %3C 32; i++) %7B%0A      numOnes += ((n & (1 %3C%3C i)) == 0) ? 0 : 1;%0A    %7D%0A%0A    return numOnes;%0A  %7D%0A%7D%0A

Add BruteForce solution to NextNumber