1.

22. What will be the output of the following programint a, b=4;for(a=6; a

Answer»

uired ANSWER:-

Correct Co‎de:

int a, b=4;

for(a=6;a<=24;a+=6)    {

  if(a%b==0)

    break;

}

System.out.println(a);

Output:

12

Explanation:

  • The GIVEN loop iterates in the range 6 to 24.
  • Here, initial value of a is 6. After each iteration, its value is incremented by 6.
  • So, when a is 6, a%b==0 is FALSE and so, the break statement will not be executed.
  • After the first iteration, a becomes 12 i.e., its value is incremented by 6. So, a%b==0 becomes TRUE as 12 is divisible by 4. So, the break statement is executed. Loop is terminated at this point.
  • Final value of a becomes 12 which is displayed on the screen.

See the attachment for output.

•••♪



Discussion

No Comment Found