Java OCA OCP Practice Question 1119

Question

What is the result of the following?

String[] s = new String[] { "Downtown", "Uptown", "Brooklyn" }; 
String[] times = new String[] { "Day", "Night" }; 
for (int i = 0, j = 0; i < s.length 
        && j < times.length; i++; j++) 
{ 
        System.out.print(s[i] + " " + times[j] + "-"); 
} 
  • A. Downtown Day-
  • B. Downtown Day-Uptown Night-
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


C.

Note

Multiple update expressions are separated with a comma rather than a semicolon.

This makes Option C correct.




PreviousNext

Related