1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
AfilCa [17]
3 years ago
8

You are given an unsorted array x of elements that implement the Comparable interface. There are no duplicates in this array. Yo

u are also given a variable m of type Comparable. Write the code needed to assign to m a reference to the median value of the array. (You may modify the array x by rearranging its elements.)NOTE: The median of a set of values is the value in the set such that there are as many values that are greater as there are that are less. For purposes of THIS exercise, if the array has an even number of members, the median is the greater of the two middle values.
EXAMPLE 1: Given "bob" "carol" "ted" "alice" "fred" the median is "carol" because there are "bob" and "alice" are less than "carol" and "fred" and "ted" are greater.
EXAMPLE 2: Given "bob" "carol" "ted" "alice" "fred" "sue", the middle two values are "carol" and "fred" and so in THIS exercise we would consider the greater to be the median.
Computers and Technology
1 answer:
Andrei [34K]3 years ago
8 0

Answer:

boolean isEven = false;

if (x.length % 2 == 0)

isEven = true;

Comparable currentMax;

int currentMaxIndex;

for (int i = x.length - 1; i >= 1; i--)

{

currentMax = x[i];

currentMaxIndex = i;

for (int j = i - 1; j >= 0; j--)

{

if (((Comparable)currentMax).compareTo(x[j]) < 0)

{

currentMax = x[j];

currentMaxIndex = j;

}

}

x[currentMaxIndex] = x[i];

x[i] = currentMax;

}

Comparable a = null;

Comparable b = null;

if (isEven == true)

{

a = x[x.length/2];

b = x[(x.length/2) - 1];

if ((a).compareTo(b) > 0)

m = a;

else

m = b;

}

else

m = x[x.length/2];

You might be interested in
In 1981, Ian Murphy broke into the AT&amp;T online computer system and changed their clocks, allowing people to make calls durin
poizon [28]
A. intentionally or recklessly disrupt, degrade, or destroy information or services on the computer
5 0
2 years ago
Which of the following is the most effective password?
zzz [600]
I would have to say that the M3(ury would be the MOST effective, because it has more capitals, numbers, and symbols, which would make it harder to hack into.
5 0
3 years ago
Read 2 more answers
Which programming language looks similar to human languages?
Fynjy0 [20]
There is only one programming language that is closest to a human language and is the most easy to learn other than HTML or CSS. 

That language would be AppleScript. for both its simplicity and power, it has become an ideal language for basic Apple programmers to learn. 
5 0
3 years ago
If you like to play graphic-intensive games on your computer and you find that your computer can't keep up, you can add a ______
nikklg [1K]
The answer is - video card
3 0
3 years ago
A page break can be prevented from being added before or after a heading by using the keyword _____ in the page-break-before or
Sedaia [141]

Answer:

avoid

Explanation:

<h2><u>Fill in the blank </u></h2>

A page break can be prevented from being added before or after a heading by using the keyword <u>avoid</u>  in the page-break-before or page-break-after properties.

3 0
3 years ago
Other questions:
  • You visit two websites about inventions of the 21st century. One has .edu in the URL address and the other has .com. Which site
    6·2 answers
  • What will be the output of the following Python code? class A: def test1(self): print(" test of A called ") class B(A): def test
    15·1 answer
  • Define function print_popcorn_time() with parameter bag_ounces. If bag_ounces is less than 3, print "Too small". If greater than
    15·1 answer
  • python An instance variable named counter of type int An instance variable named limit of type int. A constructor that takes two
    15·1 answer
  • The MAC address is a _____ bit number.
    10·2 answers
  • Wamna play mm2<br><br><br>imma send u my username​
    11·1 answer
  • Explain the emerging trends in microcomputer technology in relation to size​
    11·1 answer
  • What Is the device used to produce hard copies from personal computer ​
    5·2 answers
  • ____________ are designed to delete temporary files (such as deleted files still in the Recycle Bin, temporary Internet files, t
    10·2 answers
  • Fill in the blank: the final step of the dhcp discovery process is known as ______. Multiple choice, shuffle.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!