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
Using a conversation voice is part of:
MaRussiya [10]
Need more information
4 0
3 years ago
Who tryna trade in gta my psn is xMadOrNawx-_-
barxatty [35]
Ok I’ll add you to day
5 0
2 years ago
Read 2 more answers
A student who used a regression model that included indicator variables was upset when receiving only the following output on th
jeka57 [31]

Answer:

This is a multicolinearity problem and the student should determine the variable(s) that cause(s) the problem and remove it.

Explanation:

This information means that there exists a linear combination between the independent variables. The problem might have developed due to multicolinearity producing almost perfectly linearly dependent columns.

This could also be as a results of single matrix created when the student use an incorrect indicator variables and included an additional indicator column which created linearly dependent columns.

4 0
3 years ago
Ashley Baker has been the webmaster for Berryhill Finance only ten days when she received an e-mail that threatened to shut down
Natasha_Volkova [10]

Answer:

cyber-extortion

Explanation:

Ashley Baker has been the webmaster for Berryhill Finance only ten days when she received an e-mail that threatened to shut down Berryhill's website unless Ashley wired payment to an overseas account. Ashley was concerned that Berryhill Finance would suffer huge losses if its website went down, so she wired money to the appropriate account. The author of the e-mail successfully committed cyber-extortion.

7 0
3 years ago
What is the purpose of a mail merge field.
coldgirl [10]

adding merge fields is a way to personalize a document with information from the data source. The merge fields come from the column headings in the data source.

:)

3 0
3 years ago
Other questions:
  • To change the print orientation from portrait to landscape, tap or click the ____ button on the print preview tab.
    15·1 answer
  • Write a program that finds the largest in a series of numbers entered by the user.The program must prompt the user to enter numb
    12·1 answer
  • Discuss the types of data that business might collect and how the business could use that data to drive decision-making in a spe
    15·1 answer
  • What is the purpose of a primary key?
    5·1 answer
  • Which of the selections below represents a recursive query?
    12·1 answer
  • Which of the following would be better communicated with an image than with text?
    9·1 answer
  • Private BLANK are cloud services available to members of a particular organization.
    6·1 answer
  • When you heat a pot on a stove, the handle gets warm. which type of heat transfer is possible
    10·2 answers
  • 1k bits equals to how many bits
    12·1 answer
  • Give an example of what Artificial Intelligence application most popular is used on a daily basis.
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!