adplus-dvertising
frame-decoration

Question

What is the output of the below Java program with WHILE, BREAK and CONTINUE?
int cnt=0;
while(true)
{
  if(cnt > 4)
    break;
  if(cnt==0)
  { 
    cnt++;
    continue;
  }
  System.out.print(cnt + ",");
  cnt++;
}

a.

0,1,2,3,4,

b.

1,2,3,4,

c.

1,2,3,4

d.

Compiler error

Posted under Java Programming

Answer: (b).1,2,3,4,

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of the below Java program with WHILE, BREAK and CONTINUE?