← Back to Arrays
Question 222
Count Occurrences of a Value
Count Occurrences of a Value
Sometimes you need to know how many times a specific value appears in an array. Keep a counter at 0, loop through every element, and each time an element equals the target value, add one to the counter. In this exercise the target is 5. Print 'Count: ' followed by how many times 5 appears in the array.
Expected Output:
Count: 3= newline. No newline after the last line.
Hints4 available
Sign in to use hintsTopics:
Arrays
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.