loop constructs

Quiz Guidelines

 

Multiple Choice Question

QID: 
42

Which of the following for statements are valid?

A.

for(;;){}

B.

for(int i;;){}

C.

for(int i;;i++){}

D.

for(int i=0;;i++){}

E.

int i = 0;
for(;;i++){}

F.

for(;true;){}

G.

for(int i=0;true;i++);

 

Multiple Choice Question

QID: 
4

What will the following program print?

class LoopTest{

      public static void main(String args[]) {

             int counter = 0;

             outer:

                   for (int i = 0; i < 3; i++) {

             middle:

                  for (int j = 0; j < 3; j++) {

             inner:

                  for (int k = 0; k < 3; k++) {

                         if (k - j > 0) {

             break middle;

                        }

                    counter++;

            }

     }

}

          System.out.println(counter);

    }

}

Select 1 option

A. 2

B. 3

C. 6

D.7

E. 9