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

Accumulation Logic

Mark
< Prev
Next >

A program uses a for loop to calculate a running total by doubling the loop control variable in each iteration.

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++) {
            sum += i * 2;
        }
        System.out.println(sum);
    }
}
A

20

B

40

C

10

D

30

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|