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:
-
Is called countOf
-
Takes two parameters in this order: an array of ints and an int.
-
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
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