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 each(int i in list) {
System.out.println(i);
if (i==10) terminate;
}
B.
public static void foo(int[] list) {
for(int i=0; i < list.length; i++) {
System.out.println(i);
if (i==10) continue;
}
C.
public static void foo(int[] list) {
for(int i:list) {
System.out.println(i);
if (i==10) break;
}
D.
public static void foo(int[] list) {
while(list.length > 0) {
System.out.println(i);
if (i==10) break;
}
E.
public static void foo(int[] list) {
for(int i=0; i < list.length; i++) {
System.out.println(i);
if (i==10) break;
}