Analyze the given program segment and answer the following questions:


for(int i=3;i<=4;i++ ) {
for(int j=2;j<i;j++ ) {
System.out.print("" ); }
System.out.println("WIN" ); }
  1. How many times does the inner loop execute?
  2. Write the output of the program segment.

Views 23

Answer:

  1. Inner loop executes 3 times.
    (For 1st iteration of outer loop, inner loop executes once. For 2nd iteration of outer loop, inner loop executes two times.)

  2. Output:
    WIN
    WIN

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.