Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 6: Array
Start Practice TestPractice Test
About Exam
easy Solved by 1 students

Enhanced For-Loop Type Mismatch

Mark
< Prev
Next >

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.

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.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|