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

Nested Summation

Mark
< Prev
Next >

A program uses nested loops to calculate a total based on the sum of loop indices.

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

public class QuestionTrace {

    public static void main(String[] args) {
        int total = 0;
        for (int i = 1; i <= 3; i++) {
            for (int j = i; j <= 3; j++) {
                total += i + j;
            }
        }
        System.out.println(total);
    }
}
A

21

B

24

C

18

D

27

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|