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

Array Iteration and Modification

Mark
< Prev
Next >

Consider the following code segment.

public class DoubleArray {
    public static void main(String[] args) {
        int[] numbers = {1, 2, 3, 4, 5};
        /* missing code */
        System.out.println(java.util.Arrays.toString(numbers));
    }
}

Which of the following, if used to replace /* missing code */, will correctly double the value of each element in the numbers array?

A

for (int i = 1; i <= numbers.length; i++) { numbers[i] *= 2; }

B

for (int number : numbers) { number *= 2; }

C

for (int i = 0; i < numbers.length - 1; i++) { numbers[i] *= 2; }

D

for (int i = 0; i < numbers.length; i++) { numbers[i] *= 2; }

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|