How many base cases can we have for a recursive function?
<p>I have a method <code>rand2()</code> that <code>returns 0 or 1</code> randomly.</p>

<p>I am trying to create a method 
<code>rand3()</code> which will use <code>rand2()</code> and <code>return 0,1,2</code> 
with an equal probability.</p>

<p>I came up with a recursive solution that considers 4 combinations of 0,1.</p>

<p>All in all I wrote this function, with more than 1 base case, in a hope that it will work. </p>

<p>But it seems like recusive functions can't have more than one base case. </p>

<p>Here is my Code:</p>

<pre><code>public static int rand3(){
        String str = "";
        str+= rand2();
        str+= rand2();
        System.out.println(str);

        if(str=="00")
            return 0;
        else if(str=="11")
            return 1;
        else if( str=="01")
            return 2;          
        else
            return rand3();
    }
</code></pre>

<p>What am I missing ?</p>