How to you write this s = ( (n % 2 ) == 0 ? "0" : "1") +s; as an if-else statement? : <p>I have this method in java:</p>

<pre><code>public static string intToBinary(int n)
{
    string s = "";
    while (n &gt; 0)
    {
        s =  ( (n % 2 ) == 0 ? "0" : "1") +s;
        n = n / 2;
    }
    return s;
}
</code></pre>

<p>I'd like to write it without the question mark. I tried this: </p>

<pre><code>public static String intToBinary(int n)
    {
        String s = "";
        while (n &gt; 0){
            if ((n%2)==0) {
                s = "0";
            } else {
                s = "1";
            }
           s += s;
           n = n / 2;
        }
        return s;
    }
</code></pre>

<p>Doesn't seem to work though. Does anyone know why? </p>

<p>Insight would be much appreciated. </p>
