Enhanced For-Loop Type Mismatch
What is the reason the following code segment will not compile?
public class Test {
public static void main(String[] args) {
int[] testGrades = {95, 88, 76, 100, 82};
for (String grade : testGrades) {
System.out.println(grade);
}
}
}
A
The array initializer syntax is incorrect due to misplaced commas.
B
The for-loop header is missing a colon between the variable and the array.
C
There is no compilation error; the code compiles successfully.
D
The loop variable is declared as String even though the array holds int values.
Question Leaderboard
Not enough data yet to show leaderboard.
