PPT Slide
Writing Methods--Flawed Example
* Calculate the recurrence relation, r(n) = r(n-1) +
* r(n-2) - r(n-3), where: r(1)=1, r(2)=2, r(3)=3, n>=1.
* @param is the value of recurrence relation to calculate.
* @return the integer value of the recurrence relation at n.
public int recurrence (int iN) {
util.ASSERT(iN >= 1, “int param is less than 1”);
if (iN == 1) iReturnVal = 1;
else if (iN == 2) iReturnVal = 2;
else if (iN == 3) iReturnVal = 3;
iReturnVal = recurrence (iN-1) +
recurrence(iN-2) - recurrence(iN-3);