Enhanced For Loop Array Iteration
Consider the following code segment. Which of the following, if used to replace /* missing code */, correctly prints each element of the testGrades array on a new line using an enhanced for loop?
public class PrintGrades {
public static void main(String[] args) {
int[] testGrades = {90, 80, 100, 85, 92};
/* missing code */
}
}
A
for (int i = 0; i < testGrades.length; i++) { System.out.println(testGrades[i]); }
B
for (int grade : testGrades) { System.out.println(grade); }
C
for (int grade : testGrades) System.out.print(grade);
D
for (int grade = 0; grade < testGrades.length; grade++) { System.out.println(grade); }
Question Leaderboard
Not enough data yet to show leaderboard.
