Question

After the break statement in (a) is executed in the following loop, which statement is executed? Show the output. After the continue statement in (b) is executed in the following loop, which statement is executed? Show the output.

a.

for(int i = 1; i < 4; i++) {
  for(int j = 1; j < 4; j++) {
    if(i * j > 2)
      break;
    System.out.println(i * j);
  }
  System.out.println(i);
}

b.

for(int i = 1; i < 4; i++) {
  for(int j = 1; j < 4; j++) {
    if(i * j > 2)
      continue;
    System.out.println(i * j);
  }
  System.out.println(i);
}

Solution

Verified
Answered 1 year ago
Answered 1 year ago
Step 1
1 of 2

Case A: the break statement will be followed by the last println statement that outputs the current value of the i control variable\textbf {current value of the i control variable}.

Case B: the continue statement is followed by the increment of the value of j control variable\textbf {increment of the value of j control variable}.

The output is in both cases: 1 (i = 1, j = 1, 1 * 1) 2 (i = 1, j = 2, 1 * 2) 1 (i = 1) 2 (i = 2, j = 1, 2 * 1) 2 (i = 2) 3 (i = 3)

Create an account to view solutions

By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Continue with GoogleContinue with Facebook

Create an account to view solutions

By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Continue with GoogleContinue with Facebook

More related questions

1/4

1/7