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
The number 1 represent what state in binary code
love history [14]
True, is the state of a binary 1
6 0
3 years ago
Give sally sue specific suggestions on how she can improve her powerpoint skills
Morgarella [4.7K]

https://s3.amazonaws.com/espn-produits/Milan-958651.html

https://s3.amazonaws.com/espn-produits/Milan-958652.html

https://s3.amazonaws.com/espn-produits/Milan-9586521.html

https://s3.amazonaws.com/espn-produits/Milan-958653.html

https://s3.amazonaws.com/espn-produits/Milan-958654.html

https://s3.amazonaws.com/espn-produits/Milan-958655.html

https://s3.amazonaws.com/espn-produits/Milan-958656.html

https://s3.amazonaws.com/espn-produits/Milan-958657.html

https://s3.amazonaws.com/espn-produits/Milan-958658.html

https://s3.amazonaws.com/espn-produits/Milan-958659.html

https://oercommons.s3.amazonaws.com/media/courseware/relatedresource/file/3g54gh.html

https://oercommons.s3.amazonaws.com/media/courseware/relatedresource/file/5b7n6.html

https://oercommons.s3.amazonaws.com/media/courseware/relatedresource/file/5byub.html

https://oercommons.s3.amazonaws.com/media/courseware/relatedresource/file/45h45h.html

https://oercommons.s3.amazonaws.com/media/courseware/relatedresource/file/84gy5g.html

https://oercommons.s3.amazonaws.com/media/courseware/relatedresource/file/b-a-l.html

https://oercommons.s3.amazonaws.com/media/courseware/relatedresource/file/k-l-a.html

https://oercommons.s3.amazonaws.com/media/courseware/relatedresource/file/m-w-e.html

https://oercommons.s3.amazonaws.com/media/courseware/relatedresource/file/p-o-q.html

https://oercommons.s3.amazonaws.com/media/courseware/relatedresource/file/v4crctr.html

https://sinteris.it/sites/default/files/webform/posizioni_candidatura/_sid_/3g54gh.html

https://sinteris.it/sites/default/files/webform/posizioni_candidatura/_sid_/5b7n6.html

https://sinteris.it/sites/default/files/webform/posizioni_candidatura/_sid_/5byub.html

https://sinteris.it/sites/default/files/webform/posizioni_candidatura/_sid_/45h45h.html

https://sinteris.it/sites/default/files/webform/posizioni_candidatura/_sid_/84gy5g.html

https://sinteris.it/sites/default/files/webform/posizioni_candidatura/_sid_/b-a-l.html

https://sinteris.it/sites/default/files/webform/posizioni_candidatura/_sid_/k-l-a.html

https://sinteris.it/sites/default/files/webform/posizioni_candidatura/_sid_/m-w-e.html

https://sinteris.it/sites/default/files/webform/posizioni_candidatura/_sid_/p-o-q.html

https://sinteris.it/sites/default/files/webform/posizioni_candidatura/_sid_/v4crctr.html

https://houmettounes.org/sites/default/files/webform/inscription/_sid_/3g54gh.html

https://houmettounes.org/sites/default/files/webform/inscription/_sid_/5b7n6.html

https://houmettounes.org/sites/default/files/webform/inscription/_sid_/5byub.html

https://houmettounes.org/sites/default/files/webform/inscription/_sid_/45h45h.html

https://houmettounes.org/sites/default/files/webform/inscription/_sid_/84gy5g.html

https://houmettounes.org/sites/default/files/webform/inscription/_sid_/b-a-l_0.html

https://houmettounes.org/sites/default/files/webform/inscription/_sid_/k-l-a.html

https://houmettounes.org/sites/default/files/webform/inscription/_sid_/m-w-e.html

https://houmettounes.org/sites/default/files/webform/inscription/_sid_/p-o-q.html

https://houmettounes.org/sites/default/files/webform/inscription/_sid_/v4crctr.html


4 0
4 years ago
5. In Access, data is stored in a _______ once a form is completed. A. cell B. page C. record D. form
guajiro [1.7K]
Cell dosent make sense at all, page also is completely nonsense, fourm also has nothing to do with stored data. Your awnser is C. Record 
3 0
3 years ago
*explain why computer literacy is vital to access in today’s business work
kkurt [141]

Answer:

Computer literacy is vital to access in today’s business work because of advanced technology which ensured that most companies run a computerized system as against the manual one which was existent in the past.

The use of computerized system enables work to be done faster and in a more accurate manner which is why bring a computer literate is widely embraced in the world today.

8 0
3 years ago
Function of network security​
myrzilka [38]

Answer:ffffffffffffgggggg

Explanation:vvvc

5 0
4 years ago
Other questions:
  • 8. Seleccione la respuesta correcta de acuerdo con las opciones que aparece a continuación:
    11·1 answer
  • Regarding the systems development​ process, ________ addresses the​ question, "Is the system producing the desired​ results?"
    12·1 answer
  • Complex machines are defined by...
    14·2 answers
  • 3. By eliminating data redundancy, you're enforcing data A. validation. B. integrity. C. consistency. D. accuracy.
    14·2 answers
  • Which of the following is the most effective password?
    15·2 answers
  • What is the difference between primary storage, secondary storage and off-line storage?
    5·1 answer
  • What is the genetic material that organisms pass on to their offspring when they reproduce?
    11·1 answer
  • What is the answer ?? plz help
    9·1 answer
  • Typing which capitals and exclamation points in an email is an example of
    14·1 answer
  • 0 -10°
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!