(Intro to java) Write a static method named count that accepts an array of integers and a target integer value as parameters and returns the
(Intro to java)
Write a static method named count that accepts an array of integers and a target integer value as parameters and returns the number of occurrences of the target value in the array. For example, if a variable named list refers to an array containing values {3, 5, 2, 1, 92, 38, 3, 14, 5, 73, 5} then the call of count(list, 3) should return 2 because there are 2 occurrences of the value 3 in the array.
Test your code with the following class:
public class TestCount {
public static void main(String[] args) {
int[] list = {3, 5, 2, 1, 92, 38, 3, 14, 5, 73, 5};
System.out.println(count(list, 3)); // 2
System.out.println(count(list, 5)); // 3
System.out.println(count(list, 42)); // 0
}
// your code goes here
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started