Exit 1Z0-850 Java SE 5 and 6, Certified Associate
Question 4 of 5
0% complete
Q4 Single choice

You need an algorithm that must:

.Iterate through an array of primitive integers
.

Print the value of each array element in index order If the value of the element is equal to 10, print the value of the element, and then terminate the iteration Which method correctly implements the algorithm?

  • A

    public static void foo(int[] list) {for(int i:list) {System.out.println(i);if (i==10) break;}

  • B

    public static void foo(int[] list) {while(list.length > 0) {System.out.println(i);if (i==10) break;}

  • C

    public static void foo(int[] list) {for(int i=0; i < list.length; i++) {System.out.println(i);if (i==10) break;}

  • D

    public static void foo(int[] list) {for(int i=0; i < list.length; i++) {System.out.println(i);if (i==10) continue;}

  • E

    public static void foo(int[] list) {for each(int i in list) {System.out.println(i);if (i==10) terminate;}