Question: Now we'll go completely from scratch. The task here is to write a method that: Is called countOf Takes two parameters in this order: an

Now we'll go completely from scratch. The task here is to write a method that:

  1. Is called countOf

  2. Takes two parameters in this order: an array of ints and an int.

  3. Returns the number of times the second int occurs in the array.

You will have a main method to do your own testing, but before this will even run, you will need to get the basic components of the method implemented (a complete signature and a return statement, even if it returns the wrong thing).

import java.util.Arrays;

public class CountOf {

//Implement your method here. //If you look back at previous examples //and follow the directions, you //shouldn't have too much trouble.

//The main is for you to test things, but //you don't need to touch it if you don't //want to. public static void main(String[] args) { int[] testData = {1, 2, 1, 2, 1, 2, 1, 2};

System.out.println("1 occurs " + countOf(testData, 1) + " times in " + Arrays.toString(testData) + "."); System.out.println("2 occurs " + countOf(testData, 2) + " times in " + Arrays.toString(testData) + "."); } }

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!