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]
2 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]2 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
Translate the following pseudocode for randomly permuting the characters in a string into a C++ program.
Svetllana [295]

Answer:

d

Explanation:

salak sensin kolay gelsin

6 0
2 years ago
A common and extremely useful feature of most online dictionaries is
choli [55]
A common and extremely useful feature of most online dictionaries is <em />interoperable browser.
4 0
3 years ago
Information that indicates ground air or navy force levels or dispositions is what security?
AlexFokin [52]

Information that indicates ground air or navy force levels or dispositions is <u>confidential</u> security.

Security for a country's higher organizations is essential for a nation's protection.

Serious information like the nuclear organizations, army, navy, and ground air is at a higher risk for threats and hence requires higher security.

The information in such higher organizations is kept confidential and no third person is allowed access to the code of conduct of such organizations.

If information is leaked from the ground air or from navy force levels then there can be serious consequences for it. Hence, such information is always kept under confidential security.

To learn more about security, click here:

brainly.com/question/25375059

#SPJ4

8 0
1 year ago
Which term refers to the technical structure of the software, how users interact with the software, and how the software is phys
mars1129 [50]
The Answer is <span> Architecture</span>
7 0
3 years ago
What protocol suite below is the most commonly used protocol for local area network (lan) communication?
grandymaker [24]
Answer TCP/IP is the most common protocol in Local Area Networks.
3 0
3 years ago
Other questions:
  • Which of the following consists of electronic components that store instructions?
    10·1 answer
  • 7. The penalties for a first-time DUI charge include a fine of __________. A. up to $500 for a BAL of .08 to .15 B. $500-$1,000
    5·1 answer
  • Why is the lack of a sense of humor a serious limitation for AI?
    6·1 answer
  • Suppose a process in Host C has a UDP socket with port number 6789. Suppose both Host A and Host B each send a UDP segment to Ho
    8·1 answer
  • Why is it NOT a good practice to save everything on the desktop?
    6·2 answers
  • You are hired by a game design company and one of their most popular games is The Journey. The game has a ton of quests, and for
    12·2 answers
  • A person's oral communication skills can give either a positive or negative first impression.
    12·1 answer
  • Girls question <br> who wants to go out ;p
    11·2 answers
  • Vadik is creating a program where the user inputs their grade level and the program tells them which sports teams they are allow
    9·2 answers
  • 5. What skill is unique to reading online?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!