Question: (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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!