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

Which of the following lines correctly replaces the missing line so that each element of testGrades is printed 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 line: Use an enhanced-for loop to print each test grade on a new line.
    }
}
A

for (int grade = 0; grade < testGrades.length; grade++) { System.out.println(grade); }

B

for (int grade : testGrades) { System.out.println(grade); }

C

for (int i = 0; i < testGrades.length; i++) { System.out.println(testGrades[i]); }

D

for (int grade : testGrades) System.out.print(grade);

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