What is the final value of ctr when the iteration process given below, executes?

int ctr = 0;
for(int i = 1; i <= 5; i++)
    for(int j = 1; j <= 5; j += 2)
        ++ctr;

Long Answer
Views 82

Answer:

The final value of ctr is 15.

The outer loop executes 5 times. For each iteration of outer loop, the inner loop executes 3 times. So the statement ++ctr; is executed a total of 5 x 3 = 15 times.

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.