| preferred AP College board partner for AP classes
AP Computer Science A/Unit 6: Array
Start Practice TestPractice Test
About Exam
easy Solved by 3 students
Enhanced For-Loop Type Mismatch
< Prev
Next >

What prevents the following code from compiling?

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

There is no compilation error; the code compiles successfully.

B

The array initializer syntax is incorrect due to misplaced commas.

C

The loop variable is declared as String even though the array holds int values.

D

The for-loop header is missing a colon between the variable and the array.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy