Java OCA OCP Practice Question 1115

Question

Which of the following is equivalent to this code snippet given an array of String objects?

for (int i=s.length-1; i>=0; i--) 
       System.out.println(s[i]); 
  • A. for (String f = s) System.out.println(f);
  • B. for (String f : s) System.out.println(f);
  • C. for (String f s) System.out.println(it);
  • D. None of the above


D.

Note

Options A and C do not compile as they do not use the correct syntax for a for-each loop.

The for-each loop is only able to go through an array in ascending order.

It is not able to control the order, making Option C incorrect.

Option D is the answer.




PreviousNext

Related