For each call below to the following method, write the output that is produced,
ID: 3645444 • Letter: F
Question
For each call below to the following method, write the output that is produced, as itwould appear on the console:
public static void mystery(int n) {
System.out.print(n + " ");
if (n > 10) {
n = n / 2;
} else if (n < 10) {
n = n * 2;
}
if (n % 2 == 1) {
n++;
} else {
n--;
}
System.out.println(n);
}
Method Call Output
mystery(4);
mystery(30);
mystery(-6);
mystery(18);
mystery(15);
____________________________________________
____________________________________________
____________________________________________
____________________________________________
____________________________________________
Explanation / Answer
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.