Solved

Which of the Following Methods Would Properly Compute the Value

Question 12

Multiple Choice

Which of the following methods would properly compute the value of x % y (x mod y) recursively, assuming that x and y are not negative numbers?


A) public int recursiveMod(int x, int y)
{
If (x < y) return y;
Else return recursiveMod(x, y - x) ;
}
B) public int recursiveMod(int x, int y)
{
If (x == y) return 0;
Else return recursiveMod(x - y, y) + 1;
}
C) public int recursiveMod(int x, int y)
{
If (x < y) return x;
Else return recursiveMod(x - y, y) + 1;
}
D) public int recursiveMod(int x, int y)
{
If (x < y) return x;
Else return recursiveMod(x - y, y) ;
}
E) public int recursiveMod(int x, int y)
{
While (x > y)
X = x - y;
Return x;
}

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions