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
Various types of mouse pointer<br>​
g100num [7]

Answer:

Text Pointer

Busy Pointer

Link Pointer

Precision Pointer

Standard Pointer

Help Pointer

Background Busy Pointer

4 0
2 years ago
your brother has made a battery operated torch by using 2 cells &amp; has come to ask you how he may make the torch more powerfu
torisob [31]

Answer: Add more cells in series.

Explanation:

Adding more cells in series will add voltage which will increase the power.

5 0
3 years ago
Mary is proofreading an eBook. Sometimes she has to scroll several pages at a time. Which key on the numeric keypad will help he
Leto [7]
The number key 2 will help her scroll down.
3 0
3 years ago
Read 2 more answers
Define a method named swapValues that takes an array of four integers as a parameter, swaps array elements at indices 0 and 1, a
Luba_88 [7]

The program is an illustration of arrays.

Arrays are used to hold multiple values.

The program in java, where comments are used to explain each line is as follows:

import java.util.*;

public class Main{

   //This defines the method

public static int[] swapValues(int[] arr) {

   //This swaps the first and second array elements

       int temp = arr[0];

       arr[0] = arr[1];   arr[1] = temp;

   //This swaps the third and fourth array elements

       temp = arr[2];

       arr[2] = arr[3];   arr[3] = temp;

   //This returns the swapped array to main

       return arr;

}

//The main method begins here

   public static void main(String[] args) {

       //This creates a Scanner object

       Scanner input = new Scanner(System.in);

 //This declares an array of 4 elements

 int[] intArray = new int[4];

 //This gets input for the array

 for(int i = 0; i<4;i++){

     intArray[i] = input.nextInt();

 }

 //This calls the swapValues method

 intArray=swapValues(intArray);

 //This prints the swapped array

 for (int i = 0; i < 4; i++){

 System.out.print( intArray[i]+ " ");     }

}  

}

At the end of the program, the elements are swapped and printed.

Read more about similar programs at:

brainly.com/question/14017034

6 0
3 years ago
What does CRUD programming means and why do we need to learn it?
Slav-nsk [51]

Answer:

CRUD Meaning : CRUD is an acronym that comes from the world of computer programming and refers to the four functions that are considered necessary to implement a persistent storage application: create, read, update and delete.

Why we need to learn it? : The ability to create, read, update and delete items in a web application is crucial to most full stack projects. CRUD is too important to be ignored, so learning it first can really improve confidence within unfamiliar stacks.

6 0
2 years ago
Other questions:
  • Which type of attack modifies the fields that contain the different characteristics of the data that is being transmitted?
    7·1 answer
  • You '' friend or ''like'' a page o your favorite social media page that advertises a
    10·1 answer
  • If a computer is capable only of manipulating and storing integers, what di themselves? How are these difficulties overcome
    13·1 answer
  • Which of the following is an object-oriented prototype-based language? Java Pike REBOL MATLAB
    9·1 answer
  • What does the binary odometer show about representing large numbers?
    8·1 answer
  • What process periodically validates a user’s account, access control, and membership role on inclusion in a specific group?a. Re
    12·1 answer
  • Please give me correct answer<br><br>please give me very short answer​
    13·1 answer
  • Your welcome 95 points gg
    10·2 answers
  • What are 5 good movies like The Breakfast Club or 8 Mile?
    14·2 answers
  • Find out about the different technological solutions available for interconnecting LANs to from larger networks such as wide are
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!