Given an integer, return its binary representation. You cannot use any Integer.toXXXString methods
A single loop would be preferable.

public static String toBinaryString(int n) {
    char[] buffer = new char[32];
    for (int i = buffer.length - 1; i &gt;= 0; i--) {
        buffer[i] = '0' + (n &amp; 1);
        n &gt;&gt;&gt;= 1;
    }
    return new String(buffer);
}