Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a static method named evenBeforeOdd that accepts an array of integers as a

ID: 3643874 • Letter: W

Question

Write a static method named evenBeforeOdd that accepts an array of integers as a parameter and rearranges its elements so that all even values appear before all odds. For example, if the following array is passed to your method:
int[] numbers = {5, 2, 4, 9, 3, 6, 2, 1, 11, 1, 10, 4, 7, 3};
Then after the method has been called, one acceptable ordering of the elements would be:
{4, 2, 4, 10, 2, 6, 3, 1, 11, 1, 9, 5, 7, 3}
The exact order of the elements does not matter, so long as all even values appear before all odd values. For example, the following would also be an acceptable ordering:
{2, 2, 4, 4, 6, 10, 1, 1, 3, 3, 5, 7, 9, 11}
Do not make any assumptions about the length of the array or the range of values it might contain. For example, the array might contain no even elements or no odd elements. You may assume that the array is not null.
If the method is modeled after a bubble sort, expected output is:
[2, 4, 6, 2, 10, 4, 5, 9, 3, 1, 11, 1, 7, 3]

import java.util.*;
public class EvenBeforeOdd {

public static void main(String[] args) {
int[] numbers = {5, 2, 4, 9, 3, 6, 2, 1, 11, 1, 10, 4, 7, 3};
evenBeforeOdd(numbers);
System.out.println(Arrays.toString(numbers));
}

// *** Your method code goes here ***

} // End of EvenBeforeOdd class

Explanation / Answer

Here ya go! import java.util.*; public class EvenBeforeOdd { public static void main(String[] args) { int[] numbers = {5, 2, 4, 9, 3, 6, 2, 1, 11, 1, 10, 4, 7, 3}; evenBeforeOdd(numbers); System.out.println(Arrays.toString(numbers)); } // *** Your method code goes here *** public static void evenBeforeOdd(int[] arr) { int start=0, end=arr.length-1; while(start
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote