Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
easy

Simple Accumulation

Mark
< Prev
Next >

A loop calculates a sum by adding even integers multiplied by two and odd integers as they are.

What is printed when the following Java program is compiled and run?

public class QuestionTrace {

    public static void main(String[] args) {
        int sum = 0;
        for (int i = 1; i < 5; i++) {
            if (i % 2 == 0) sum += i * 2;
            else sum += i;
        }
        System.out.print(sum);
    }
}
A

12

B

10

C

20

D

16

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|