Can someone please help me find a method to this?


The following recursive method addeven (...) is supposed to add the even indexed values of an array, i.e., a[0] + a[2] + a[4] + … There are bugs in the method. Trace the method using test data, find the bugs, and correct them. Be thorough. The method may work on some data sets. (Hint: The error involves one line of code>)

public static int addeven(int a[], int size)

{

if (size == 2)

return a[1];

return a[size - 1] + addeven(a, size - 2) ;

}

Can do, but won't. Do your own homework, it's good for you.

I know can u guide me though
im having hard time understanding it cuz ihave no book
am isuppose to write a method for it or just correct it ??

thanks :)

Just correct it. Walk through it step by step and see where it's wrong. Make a few test lists to work on - make sure you have the edge cases covered, try it with lists of zero, one, and two elements, as well as some longer ones with both even and odd numbers of elements. Walk through the code for each list, and see what it does. Where it does the wrong thing, fix it.

It's not hard. I'm not going to do it for you. You get no more help here.

ok got it thank u

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.