Java OCA OCP Practice Question 1895

Question

Consider the following code snippet:

for (int i=i1; i<i2; i++){
        System.out.println (i);
}

i1 and i2 can be any two integers.

Which of the following will produce the same result?

Select 1 option

  • A. for (int i=i1; i<i2; System.out.println (++i));
  • B. for (int i=i1; i++<i2; System.out.println (i));
  • C. int i=i1; while (i++<i2) { System.out.println (i); }
  • D. int i=i1; do { System.out.println (i); }while (i++<i2);
  • E. None of these.


Correct Option is  : E

Note

In such a question it is best to take a sample data such as i1= 1 and i2=3 and execute the loops mentally.

Eliminate the wrong options.

Outputs of all the options are given above.

Thus, none of them is same as the original.




PreviousNext

Related