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]
4 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]4 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
I need help picture above
m_a_m_a [10]

Answer:

The 2nd one on top and The Star ones.. (sorry if its wrong

Explanation:

7 0
3 years ago
Read 2 more answers
3.6 code practice (edhesive)
Pie

largest = int(input("Enter a number: "))

print("Largest: {}".format(largest))

i = 0

while i < 5:

   num = int(input("Enter a number: "))

   if num > largest:

       largest = num

   print("Largest: {}".format(largest))

   i += 1

I hope this helps!

4 0
3 years ago
Walter is developing a website for the logistics service he offers. He wants to make the website attractive, bright, and visuall
vlada-n [284]

Walter develop the website by:

  • Registering for a domain name
  • Research for a web hosting firm.
  • Have and Prepare your content done.
  • Lastly, create or build your website.

<h3>Can a person develop my own website?</h3>

The use of CMS that is website building platform is known to be a type of platform that can also help one in building websites and handling or monitoring its online content.

Note that by following the above steps,  Walter can create or develop his own website.

Learn more about website from

brainly.com/question/13171394

#SPJ1

6 0
2 years ago
Many computer programs contain ____ that detail the specific instructions a computer should perform (in a specific order) to car
nikklg [1K]

Answer:

Algorithms.

Explanation:

Computer system is an electronic machine that receives input data, processes or executes these data and outputs the results. It comprises of two parts, the hardware and software components.

The computer receives data created by a process and inputted by individuals. The software components are the operating system and the application softwares running in the operating system. The application software follows a well defined stages of task to execute a task. This is called algorithm.

The application uses the algorithm to execute the task on the input data to give the required result.

8 0
3 years ago
Whats the size of a short bond paper in microsoft word?
poizon [28]
I believe the size is 8.5x11
7 0
3 years ago
Other questions:
  • Write a program to read-in a sequence of integers from the keyboard using scanf(). Your program will determine (a) the largest i
    8·1 answer
  • Pls help is very urgent and I will mark u as brainliest plsssss​
    11·2 answers
  • True or False. A modern programming EXE provides a text editor, a file manager, a compiler, a linker and loader, and tools for d
    9·1 answer
  • The main benefit of shielded twisted pair cabling over unshielded twisted pair is that STP is much more durable.
    13·1 answer
  • Online transaction processing (OLTP) and online analytical processing (OLAP) are similar MIS strategies used to help with busine
    9·1 answer
  • Which of the following is a common sense safety procedure that can help prevent electrical accidents?
    15·1 answer
  • Technology is used today in manufacturing,health care , and the transportation industry,but education has not yet embraced it? t
    12·2 answers
  • Which footing supports a long brick or concrete wall<br>​
    14·1 answer
  • How do you reset a g.mail password?
    12·2 answers
  • what motivators should the action section of your sales message include? check all that apply. a satisfaction guarantee a proof
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!