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
What are 2 ways that technology can negatively impact the environment.
Ahat [919]
By compromising human health and safety.
7 0
3 years ago
Read 2 more answers
What did I do wrong? May you please correct it for me...I was also looking on how to delay when it prints. Like when it prints a
inessss [21]

Answer:

print("\nWelcome to the impossible quiz!\n")

name = input("What's your name before we get started? ")

print("Nice to meet you, "+ name)

print("\nThe rules are very simple, get the answer right and you get 10 points. You only have one chance to get the answer right, get it wrong and you'll lose 3 points! ")

input("\nReady?\n")

user_score = 0

print("First question: Do slugs have four noses?")

answer = input('Give "F" for False or "T" for True: ')

if answer == "T":

time.sleep(2)

print("Correct, you've gained 10 points!")

user_score += 10

elif answer == "F":

time.sleep(2)

print("Incorrect, you've lost 3 points!")

user_score += -3

Explanation:

Please check the answer. However, if before answer was wrong, and we need to use time.sleep(2) for delaying printing.

4 0
3 years ago
Yaaaaaa.........
balandron [24]

Answer:

Thank you

Explanation:

Have a blessed day !

May God bless you

5 0
2 years ago
Read 2 more answers
A user saves a password on a website the user logs into from a desktop. Under which circumstances will the password be saved on
9966 [12]

Answer:

Same Browser

Explanation:

If we access some password for some website in from some computer. It will be saved in the browser of the computer. Whenever we access the website from some other computer and we want to login we need the same browser.

In this process, browser is sync by using our mailing address. Whenever we want to access the pasword of different website from some other device, we need to sync that device browser with the same mailing address.

In this process all password that are saved on other device may access from any device.

7 0
3 years ago
What character separates the file extension and the filename?
PtichkaEL [24]
A period, Filenamehere.png or .pdf or any other file extension
5 0
2 years ago
Read 2 more answers
Other questions:
  • Which type of communication is usually handwriten
    11·2 answers
  • .When an argument is passed ______________, the called method can access and modify the caller’s original data directly.
    8·1 answer
  • Which social network site has 1.5 billion actives users per month?
    15·1 answer
  • Why computer is known as data processing system?
    14·1 answer
  • Another personal question- are there any messaging sites that MIGHT work if most things are blocked via the school? I doubt anyt
    11·2 answers
  • Which device makes computers that are connected to separate segments appear and behave as if they're on the same segment? (Pleas
    11·1 answer
  • Identify the electronic community that is a social-networking site.
    5·2 answers
  • Assume the availability of a function is_prime. Assume a variable n has been associated with positive integer. Write the stateme
    15·1 answer
  • If the tax percent is 15% and tax is $36 and percent discount is 10, what is the cost price?​
    12·1 answer
  • 1. Write a statement that opens the file Customers.dat as a random access file for both reading and writing.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!