Question
USE JAVA In the box provided to answer this question, write the code for the method categorize, a method that returns a reference to an
USE JAVA
In the box provided to answer this question, write the code for the method categorize, a method that returns a reference to an array of int variables whose length is 3. The method receives a single argument numbers thats a reference to an array of int values. The method assigns values to the elements of the return result as per the following scheme: Element 0 holds the count of the number of elements in numbers that are non-positive, element 1 holds the count of positive odd-numbered elements in numbers, and element 2 holds the count of the positive even-numbered elements in numbers. Five sample runs with different array inputs are given on the Sheet for this Question. Note that showArray (again) simply displays the elements of the input array.
Sample arrays with sample Call
int[ ] numbers1 = {0, -1, 2, 2, 6};
result = categorize(numbers1);
showArray("Run 1 result:", result);
int[ ] numbers2 = {1, 5, 3, 7, 2, 1, 0, 8};
private static void showArray(String explanation, int[ ] array)
{
int len = array.length;
int indx;
System.out.println(explanation);
for (indx = 0; indx System.out.printf("%d", array[indx]);
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