Solved

If/Else Simulation For Each Call of the Method Below, Write the Value

Question 2

Essay

If/Else Simulation
For each call of the method below, write the value that is returned:
public static int mystery(int n) {
if (n < 0) {
n = n * 3;
return n;
} else {
n = n + 3;
}
if (n % 2 == 1) {
n = n + n % 10;
}
return n;
}
Method Call Value Returned
mystery(-5) _______________________________
mystery(0) _______________________________
mystery(7) _______________________________
mystery(18) _______________________________
mystery(49) _______________________________

Correct Answer:

verifed

Verified

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