subject

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. You MAY NOT use any temporary arrays to help you solve this problem. (But you may declare as many simple variables as you like, such as ints.) You also MAY NOT use any other data structures such as the ArrayList class . DO NOT use Arrays. sort in your solution. Hint: This is actually a sorting problem. In BubbleSort you tested pairs of elements and swapped them if the left element is larger than the right element. In this problem, the swap happens when the left element is odd and the right element is even. You may use the following code to test your program: If your 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

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 08:00
What is the algorithm for building a binary tree program
Answers: 2
question
Computers and Technology, 22.06.2019 18:30
Kto rozmawia z clamentain przez krótkofalówke w the walking dead w 4 epizodzie
Answers: 1
question
Computers and Technology, 24.06.2019 01:10
Create a program that will take in a single x and y coordinate as the origin. after the input is provided, the output should be all of the coordinates (all 26 coordinates read from the “coordinates.json” file), in order of closest-to-farthest from the origin.
Answers: 1
question
Computers and Technology, 24.06.2019 17:00
Anew author is in the process of negotiating a contract for a new romance novel. the publisher is offering three options. in the first option, the author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published. in the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold. in the third option, the author is paid 10% of the net price for the first 4,000 copies sold, and 14% of the net price for the copies sold over 4,000. the author has some idea about the number of copies that will be sold and would like to have an estimate of the royal- ties generated under each option. write a program that prompts the author to enter the net price of each copy of the novel and the estimated number of copies that will be sold. the program then outputs he royalties under each option and the best option the author could choose. (use appropriate named constants to store the special values such as royalty rates and fixed royalties.
Answers: 1
You know the right answer?
Write a static method named "evenBeforeOdd" that accepts an array of integers as a parameter and rea...
Questions
question
Mathematics, 08.12.2020 09:10
question
Mathematics, 08.12.2020 09:10
question
Computers and Technology, 08.12.2020 09:10
question
Mathematics, 08.12.2020 09:10
Questions on the website: 13722362