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
The prediction that the number of transistors on a chip would double about every two years is known as ________. Metcalfe's law
MaRussiya [10]

Answer:

Moore's law

Explanation:

The Moore’s law which was named after the pioneer, Gordon Moore, predicted that the number of transistors on a chip would double about every two years. This law is one of the reasons why computers became so powerful. These transistors and chips are used to make mathematical calculations and in 1965, Gordon made an observation and forecasted that the number of transistors that can be placed in any ICs doubles approximately every two years. Moore was so convinced about this prediction that he went on to co-found the biggest chips processor; INTEL. This trend has been accurate since then but has started to slow down from 2013.

5 0
2 years ago
Explain how inflation flattens the universe
DIA [1.3K]
They rise to the surface of the earth
8 0
3 years ago
Read 2 more answers
Uinjsiodj9fijsdiokjdwe0okakj09dw9j09jw09
erica [24]

Answer:

hi

Explanation:

hii

3 0
2 years ago
Read 2 more answers
Consider the following class:
Pachacha [2.7K]

Answer:

c.return Integer.compare(value, otherTemp.value)

Explanation:

The compare() method as the name implies compares two integer values. If they are equal it returns 0, if the first number is smaller it returns -1, and if the first number is greater it returns 1.

It is an Integer class method that is why you need to type Integer.compare() to call the function.

For this example, the parameters that will be compared are <em>value</em>, and <em>otherTemp.value. </em>The type of compareTo method is an integer, we need to return the result.

3 0
3 years ago
Sarah has prepared a project document about the small and medium-sized companies in the United States. While proofreading, she r
erik [133]
The answer is F7. When you click F7 it highlights key words.<span />
3 0
3 years ago
Read 2 more answers
Other questions:
  • Write a program that implement a bubble sort ?
    5·1 answer
  • Commands are organized into tabs on the
    8·2 answers
  • Manuel has set up his network so that some employees can open and view files but are unable to edit them. Others can open, view,
    10·1 answer
  • I have this assignment due TONIGHT BEFORE 10PM! Please help. 50 points for whoever will help!! Here is the assignment.
    7·1 answer
  • The diagnostic test that involves watching a computer monitor with alternating checkerboard patterns while an eeg is performed i
    11·2 answers
  • Your sister asks you if it is possible to get an office productivity suite for free. What do you tell her?
    13·1 answer
  • A security administrator plans to conduct a vulnerability scan on the network to determine if system applications are up to date
    15·1 answer
  • Complete the sentence.
    5·1 answer
  • What is a mod in programming?<br><br> Give more Java questions
    12·1 answer
  • Explain why you would use the soft on/off jumper when working on ATX system
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!