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
Universal Container wants to understand all of the configuration changes that have been made over the last 6 months. Which tool
rosijanka [135]

Answer:

Set up audit trail

Explanation:

The administrator should set up an audit trail in order to get this information.

An audit trail would give him the record of all the configuration changes that have been made in a file or a database in the last 6 months.

Audit trails can be manual or electronic. It provides history and also documentation support. It can authenticate security and also help to mitigate challenges.

4 0
3 years ago
The basic difference between RAM and ROM memory is: Question 5 options: A) RAM is nonvolatile while ROM is volatile. B) RAM is r
schepotkina [342]

The basic difference between RAM and ROM memory is RAM is read/write while ROM Is read-only.

Explanation:

  • A ROM, non-volatile memory, does not use to store data, but RAM is volatile and requires power to store data.
  • ROM is not given usually as a specification, but RAM is typically specified when buying a computer.
  • We can write data only once in ROM. However, once it is written, we can read it any number of times. RAM is the main memory in a computer, and read from and write to it much faster than other storage types. RAM is used to store files in use on the computer.

Hence the basic difference between RAM and ROM memory is RAM is read/write while ROM Is read-only.

6 0
3 years ago
How are special characters added to a Word document? Check all that apply.
MrRissso [65]

It kinda depends on what you mean by special characters

7 0
3 years ago
Read 2 more answers
Who have a ps4 ?<br> Who have 2k20? <br> Are you good a 2k20 ? <br> Add me on Ps4 eoKyriie
Lena [83]

Answer:

lol i would but i have an Xbox...

Explanation:

4 0
3 years ago
Read 2 more answers
Which of the following is not one of the goals of technical recovery team members during the recovery phase of a BCP? Normalize
Zanzabum

Answer:

Repair damage done to original systems

Explanation:

It is imperative that businesses brace up for moments or period of challenges whereby normal operation is impeded due to disruption in standard system condition. The ability of businesses to thrive and continue to deliver in these circumstances is catered for by the business continuity plan. The recovery team ensures that important processes critical to the business are restored in other to ensure that business operation isn't crippled. Once normalcy ahs been restored, the team ensures recoverabke day in the original system are taken care of. The repair of damage done is not a goal of the recovery ohase in the business continuity plan as repairsvare catered for after recovery event has been finalized.

3 0
3 years ago
Other questions:
  • Rachel uses a word processor to write short stories. However, most of her time is spent toying with the keys, rather than in wri
    13·2 answers
  • Which branch of science helps avoid or minimize stress related injuries at workplace? _____ is a branch of science that aims to
    15·1 answer
  • Where could an identity thief access your personal information?
    13·1 answer
  • An ISP is considering adding additional redundant connections to its network. Which of
    5·1 answer
  • How to control what is on the x and y axis in excel?
    13·1 answer
  • A(n) __________ describes a set of well-defined logical steps that must be taken to perform a task
    5·1 answer
  • If you do not want to keep a change made by the autocorrect feature, you can click the ____ button on the auto correction option
    12·1 answer
  • DTE just installed 500kW of solar capacity on the MCCC campus. the cost of the installation was about $3 million. what was the c
    10·1 answer
  • Name the application used for creating Presentations___
    5·2 answers
  • OSI layer for HDLC??​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!