Oracle
1Z0-850 · Question #46
1Z0-850 Question #46: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-850 to reveal the answer and full explanation for question #46. The question stem and answer options stay visible for context.
Question
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?
Options
- Apublic static void foo(int[] list) { for(each(int in list)) { System.out.println(i); if (i==10) terminate; } }
- Bpublic static void foo(int[] list) { for(int i=0; i< list.length; i++) { System.out.println(i); if (i==10) continue; } }
- Cpublic static void foo(int[] list) { for(int i:list) { System.out.println(i); if (i==10) break; } }
- Dpublic static void foo(int[] list) { while(list.length > 0) { System.out.println(i); if (i==10) break; } }
- Epublic static void foo(int[] list) { for(int i=0; i < list.length; i++) { System.out.println(i); if (i==10) break; } }
Unlock 1Z0-850 to see the answer
You've previewed enough free 1Z0-850 questions. Unlock 1Z0-850 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.