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 Solved by 1 students

For Loop Array Traversal

Mark
< Prev
Next >

Consider the following method.

public static int mystery(int[] arr) 
{
  int x = 0;
  for (int k = 0; k < arr.length; k = k + 2) 
    x = x + arr[k];
  return x;
}

Assume that the array nums is declared and initialized as follows.

int[] nums = {3, 6, 1, 0, 1, 4, 2};

What value is returned by the call mystery(nums)?

A

7

B

17

C

10

D

5

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|