Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writing a method isItEvenOdd that takes a parameter of integer array and returns TRUE, if all the even numbers, in the array,

I need help writing a method isItEvenOdd that takes a parameter of integer array and returns TRUE, if all the even numbers, in the array, comes before all the odd numbers. For example,

isItEvenOdd([9, 5, 2, 2]) -> true

isItEvenOdd([8, 3, 2, -19, 8]) -> false

isItEvenOdd([8]) -> true

isItEvenOdd([])-> true

The method begins:

 public static boolean isItEvenOdd(int[] nums) { } // end isItEvenOdd

Shellcode:

public class P3_IsEvenOdd {

public static void main(String[] args) { int[] arr1 = new int[]{10, 6, 3, 3}; boolean expectedResult = true; test(arr1, expectedResult);

int[] arr2 = new int[]{7, 2, 1, -10, 9}; expectedResult = false; test(arr2, expectedResult);

int[] arr3 = new int[]{9}; expectedResult = true; test(arr3, expectedResult);

int[] arr4 = new int[]{}; expectedResult = true; test(arr4, expectedResult); } // end main

//**********************************************************************

// a testing shell to print input array and testing result public static void test(int[] nums, boolean expectedResult) { System.out.println("Testing " + Arrays.toString(nums)); // print content of array System.out.println("expected: " + expectedResult); // print expected result boolean actualResult = isEvenOdd(nums); // call method that solves the problem System.out.println("actual: " + actualResult); // print result System.out.println((expectedResult == actualResult)? "pass" : "fail"); // testing status: pass or fail System.out.println(); // empty line between testing cases } // end test

//**********************************************************************

// actual method that solves the problem public static boolean isEvenOdd(int[] nums) { } // end isEvenOdd

} // end class P3_IsEvenOd

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

4.1 Explain multiple uses of job analysis in HR decisions.

Answered: 1 week ago