Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
easy Solved by 1 students

For Loop with Conditional Logic

Mark
< Prev
Next >

What is printed when the following code segment is executed?

public class LoopTest {
    public static void main(String[] args) {
        int count = 0;
        for(int i = 0; i < 5; i++) {
            if(i % 2 == 0)
                count += i;
            else if(i % 2 != 0)
                count -= i;
        }
        System.out.println(count);
    }
}
A

0

B

4

C

-2

D

2

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.

AI Tutor

How can I help?

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