Java OCA OCP Practice Question 1151

Question

Which of the following can fill in the blank to have the code compile successfully?

package nyc; 
public class Main { 
       public static void main(String... args) { 
          String[] s = new String[] { "A", "B", "C" }; 
          String[] times = new String[] { "Day", "Night" }; 
             for (                     i < 1; i++, j++) 
                System.out.println(s[i] + " " + times[j]); 
       } 
} 
  • A. int i=0; j=0;
  • B. int i=0, j=0;
  • C. int i=0; int j=0;
  • D. int i=0, int j=0;


B.

Note

In a for loop, the type is only allowed to be specified once.

A comma separates multiple variables since they are part of the same statement.

Option B is correct.




PreviousNext

Related