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
Lisa [10]
3 years ago
14

Write a static method middleValue that takes three int parameters, and returns a int . It should return the middle value of the

three parameters (sometimes called the median value). You may assume that all three parameters are different values (there are no duplicates).
Computers and Technology
1 answer:
anygoal [31]3 years ago
6 0

We use if-else structure to check the each possible scenario and return the median accordingly in the middleValue() method. The main is also provided so that you can test the method.

Comments are used to explain the each line.

You may see the output in the attachment.

public class Main

{

public static void main(String[] args) {

   

    //call the method for different scenarios

    System.out.println(middleValue(1, 2, 3));

    System.out.println(middleValue(1, 3, 2));

    System.out.println(middleValue(2, 1, 3));

    System.out.println(middleValue(2, 3, 1));

    System.out.println(middleValue(3, 1, 2));

    System.out.println(middleValue(3, 2, 1));

 

}

       //method that takes three int and returns an int

public static int middleValue(int n1, int n2, int n3) {

    //set the median as n1

    int median = n1;

   

    //check the situation where the n1 is the highest

    //if n2 is greater than n2 -> n1 > n2 > n3

    //if not -> n1 > n3 > n2

    if(n1 > n2 && n1 > n3){

        if(n2 > n3)

            median = n2;

        else

            median = n3;

    }

   

    //check the situation where the n2 is the highest

    //if n3 is greater than n1 -> n2 > n3 > n1

    //if not -> n2 > n1 > n3

    //note that we set the median as n1 by default, that is why there is no else part

    else if(n2 > n1 && n2 > n3){

        if(n3 > n1)

            median = n3;

    }

   

    //otherwise, n3 is the highest

    //if n2 is greater than n1 -> n3 > n2 > n1

    //if not -> n3 > n1 > n2

    //note that we set the median as n1 by default, that is why there is no else part

    else{

        if(n2 > n1)

            median = n2;

    }

   

    return median;

}

}

You may see another if-else question at:

brainly.com/question/13428325

You might be interested in
This question is related to linked-list representation of disjoint sets. Consider two sets Sx and Sy that have 3 and 5 elements,
sattari [20]

Answer:

A union (UNION(x,y)) of the sets Sx and Sy represented by x and y, respectively will perform ________4_________ update(s) of the attribute.

Explanation:

The UNION (x, y) disjoint-set data structure unites the dynamic sets that contain x and y, say Sx and Sy, into a new set.  It is called the union of the two sets. Before the union operation, the two sets are disjoint.  After the union operation, the representative of the resulting set is some member of Sx and Sy or either Sx or Sy. The sets Sx and Sy are then destroyed to remove them from the union collection S.  So, four operations are required.

8 0
3 years ago
PLS HURRY!!<br> Look at the image below!
Verizon [17]

Answer:

control

Explanation:

6 0
3 years ago
This career applies mathematical and theoretical knowledge in order to compare and produce computational solutions.
ipn [44]

Answer:

Why does love.com redirect to Verizon.

Explanation:

4 0
3 years ago
Read 2 more answers
What are the cons of using keyboard shortcuts?
Yanka [14]

Answer:

Mistakes can easily occur while using them.

4 0
3 years ago
  _______ data updates in your destination document if there are changes to the source data
konstantin123 [22]
The answer is probalay A

8 0
4 years ago
Other questions:
  • How many keywords are there in C programming language
    8·1 answer
  • Instead of typing out each co-worker's email address individually, you can use the Office Online People application to create a
    8·2 answers
  • Scale-based classification for networks allows us to differentiate PANs, LANs, MANs, and WANs. Moreover, the structure of a netw
    6·1 answer
  • What is a quick way to close the header or footer view in a microsoft word document?
    12·1 answer
  • 1. Which of the following should NOT be in a tagline?
    12·1 answer
  • The "Rudolph Rule" is best described by which of the following?
    9·1 answer
  • Select the correct answer.
    13·1 answer
  • 25 Points Asap <br> Write a Java program named Light.java that displays a light bulb shown below:
    14·1 answer
  • How to convert meters to centimeters in c programming​
    8·1 answer
  • What is a circuit breaker and how is it different from a fuse? Why do we need these two different devices?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!