Limited access

Upgrade to access all content for this subject

Consider the following non-recursive method.

public static int mystery(int x)
{
    int sum = 0;
    while (x >= 0)
   {
        sum += x;
        x--;
   }
    return sum;
}

Which of the following recursive methods are equivalent to this method?

A
public static int mystery1(int x)
 {
     if (x == 0)
        return 0;
     else
        return (x - mystery1(x - 1));
 }
B
public static int mystery2(int x)
 {
     if (x == 0)
        return 0;
     else
        return mystery2(x - 1);
 }
C
public static int mystery3(int x)
 {
     if (x == 0)
        return 0;
     else
        return x + mystery3(x - 1);
}
D
public static int mystery4(int x)
 {
     if (x == 1)
        return 0;
     else
        return x + mystery4(x - 1);
 }
E
public static int mystery4(int x)
{
     if (x == 1)
        return 1;
     else
        return x - mystery4(x - 1);
 }
Select an assignment template