Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Data Collections
Start Practice TestPractice Test
About Exam
easy

Java Array Iteration and Filtering

Mark
< Prev
Next >

Assume that the array arr has been defined and initialized as follows.

int[] arr = /* initial values for the array */ ;

Which of the following code segments correctly prints only the odd integers contained in arr?

A

for (int x : arr)
{
if (x % 2 == 1)
{
System.out.println(arr[x]);
}
}

B

for (int k = 1; k < arr.length; k++)
{
if (arr[k] % 2 == 1)
{
System.out.println(arr[k]);
}
}

C

for (int x : arr)
{
if (x % 2 == 1)
{
System.out.println(x);
}
}

D

for (int x : arr)
{
if (arr[x] % 2 == 1)
{
System.out.println(arr[x]);
}
}

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: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|