Solved

Which of the Following Methods Would Properly Compute the Value

Question 31

Multiple Choice

Which of the following methods would properly compute the value of x % y (x mod y) recursively, assuming that x and y 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

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents