Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
hard Solved by 2 students

While Loop Execution Trace

Mark
< Prev
Next >

What is printed as a result of executing the following code segment?

int result = 1;
int base = 2;
int exponent = 5;
while (exponent > 0) {
    if (exponent % 2 == 1) {
        result *= base;
    }
    base *= base;
    exponent /= 2;
}
System.out.println(result);
A

16

B

25

C

10

D

32

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|