Question
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
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