Recursive definition solution
<p>im studying for my final exam from the text book. I need an answer for this question since i couldn't solve it.</p>

<p>1)Write a recursive definition of the function multiply(int a, int b) that takes two integers and return the result of their multiplication.</p>

<p>I answered:</p>

<pre><code>Multiply(a, b) :
0 - if a or b is equal to zero.   (I got -1 here. Reason written: only 1)
a * b - (I didn't know what to write here)
</code></pre>

<p>2)
Write a recursive method that takes a linked list of integers and returns the sum of it's elements.</p>

<p>My solution was:</p>

<pre><code>int sumList(Node&lt;Integer&gt; list) {

    int temp = list.getInfo();

    if(temp == null) {
        return 0;

    } else {
        return temp + sumList(temp.getNext);
    }
}
</code></pre>

<p>I fixed it, i think:</p>

<pre><code> public int sumList(Node&lt;Integer&gt; list) {

    Node&lt;Integer&gt; temp = list;

    if(temp == null) {
        return 0;

    } else {
        return temp.getInfo() + sumList(temp.getNext());
    }
}
</code></pre>

<p>Is the solution for question 2 right?</p>
