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

Which of the following code segments correctly uses an enhanced for loop to calculate the sum of all elements in an integer array?

A

int[] nums = {2, 4, 6, 8, 10}; int sum = 0; for (int num : nums) { sum += num; }

B

int sum = 0; for (int num : nums) { sum += nums[num]; }

C

int sum = 0; for (int num : nums) { num += num; }

D

int sum = 0; for (int i = 0; i < nums.length; i++) { sum += nums[i]; }

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1singhris00011 0m 18s 82
#2geethasailaja11 0m 21s 79
#3midnightasdark11 0m 26s 74
#4y.seong202712 0m 45s 45
#5demosolasis111 0m 56s 44
#6suhanakochhar00613 2m 41s -81
#7sathilak00011 4m 54s -194
#8sailajavadlamani3312 5m 29s -239
#9bommasam00036 12h 41m -45,409
Items per page:
10
1 – 9 of 9
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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