Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instantiate an array and load it with values. Write methods to determine how many of the values in the array are odd and how many

Instantiate an array and load it with values. Write methods to determine how many of the values in the array are odd and how many are even. The methods should return arrays that contain the odds and evens.

Sample code

Sample Data :

2 4 6 8 10 12 14

1 2 3 4 5 6 7 8 9

2 10 20 21 23 24 40 55 60 61

Sample Output :

Odds - []

Evens - [2, 4, 6, 8, 10, 12, 14]

Odds - [1, 3, 5, 7, 9]

Evens - [2, 4, 6, 8]

Odds - [21, 23, 55, 61]

Evens - [2, 10, 20, 24, 40, 60]

starter code

public class OddsAndEvens

{

/**

* Return the number of even or odd elements in array.

* If odd is true then the number of odd elements is returned,

* otherwise the number of even elements is returned.

*

* numArray The input array.

* odd If true then the returned count is the number of

* odd elements. If false then the returned count is

* the number of even elements.

* return The number of odd (or even) elements in array.

*/

// Note: Since this method is private, you do not have to implement it.

// If you do implement it, then it could be helpful when writing getAllEvens

// and getAllOdds.

private static int countEm(int[] array, boolean odd)

{

return 0;

}

/**

* Return an array with the even elements of array.

*

* @param array The input array.

* @return An array containing the even elements of array.

*/

public static int[] getAllEvens(int[] array)

{

return null;

}

/**

* Return an array with the odd elements of array.

*

* @param array The input array.

* @return An array containing the odd elements of array.

*/

public static int[] getAllOdds(int[] array)

{

return null;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions