X419: Arrays - Counter Practice

The following method takes an integer array as a paramter. Write code that loops through the array to find the value 1. If 1 is found, increment a counter variable. Once the loop finishes, return the value of the counter. If the array is invalid anyway, return 0.

Examples:

oneFinder({1,1,1}) -> 3
oneFinder({1,2,3,4,5,6,7,8,9}) -> 1
oneFinder({2}) -> 0

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.