페이지 2 / 전체 2
2. 코드
public class NextBigNumber { private int nextBigNumber(int n) { int count = bitCount(n); while ( true ) { n++; if ( count == bitCount(n) ) break; } return n; } private int bitCount(int n) { String binNum = Integer.toBinaryString(n); int count = 0; for ( int inx=0; inx<binNum.length(); inx++ ) { char c = binNum.charAt(inx); if ( c == '1' ) { count++; } } return count; } public static void main(String[] args) { NextBigNumber nbn = new NextBigNumber(); int n = 78; System.out.println(nbn.nextBigNumber(n)); } }