Can't get recursive function to work in Java 
<p>I read docs about java recorsion and I thought I have understood it, but when I try to use it in the following example, it does not work as expected.</p>

<p>I a class <code>account</code>, which has <code>amount</code> and can have forther subAccount. I would have implemented one method <code>getSum</code>, which has to return the summ of the amount of the account and amount of all of its subaccount. In the following code, the call of the method <code>getSumm()</code> should return 550, but it behaves strange. can somebody help please?</p>

<pre><code>public class Balance{
    ArrayList&lt;Balance&gt; subAccounts = new ArrayList&lt;Balance&gt;();
    String accountID = null;
    Double amount = null;
    double result=0;
    public double getSum(ArrayList&lt;Balance&gt; subAccounts){

        if(subAccounts !=null &amp;&amp; subAccounts.size()&gt;0){
            for (int i = 0; i &lt; subAccounts.size(); i++) {

            result = result + getSum(subAccounts.get(i).subAccounts);

            }
        }
            else {
                return amount;
            }

        return result;
    }


    public static void main(String[] args) {
        Balance bs1 = new Balance();
        Balance bs2 = new Balance();
        Balance bs3 = new Balance();

        bs1.amount=100.0;
        bs2.amount=150.0;
        bs3.amount=300.0;
        ArrayList&lt;Balance&gt; subAccounts1 = new ArrayList&lt;Balance&gt;();

        bs2.subAccounts=null;
        bs3.subAccounts=null;
        subAccounts1.add(bs2);
        subAccounts1.add(bs3);
        bs1.subAccounts=subAccounts1;
        double sum= bs1.getSum(subAccounts1);
        System.out.println(sum);

}

}
</code></pre>
