Counting Elements in an Array
The following code segment is intended to count the number of integers in the array nums that are greater than 50. Which statement should replace /* missing code */ so that the code segment works as intended?
int count = 0;
int[] nums = {42, 67, 55, 33, 99, 78};
for (int num : nums) {
/* missing code */
}
System.out.println(count);
A
if (num > 50) count += 1;
B
if (num < 50) ++count;
C
if (num > 50) count += 1 + count;
D
if (num >= 50) count–;
Question Leaderboard
Not enough data yet to show leaderboard.
