Ask Question
16 December, 16:34

max is a method that accepts two int arguments and returns the value of the larger one. Four int variables, population1, population2, population3 and population4 have already been declared and initialized. Write an expression (not a statement!) whose value is the largest of population1, population2, population3 and population4 by calling max. Assume that max is defined in the same class that calls it.

+1
Answers (1)
  1. 16 December, 18:41
    0
    Hello, I imagine that you use Java as the programming language since you refer to classes, so I will make a small code that simulates a Java program with the descriptions you need.

    public class Example {

    public int Max (int population1, int population2, int population3, int population4) {

    int max = 0;

    if (population1 > population2 && population1 > population3 && population1 && population4) {

    max = population1;

    }

    else if (population2 > population1 && population2 > population3 && population2 && population4) {

    max = population2;

    }

    else if (population3 > population2 && population3 > population1 && population3 && population4) {

    max = population3;

    }

    else {

    max = population4;

    }

    return max;

    }

    public static void main (String[] populations) {

    Example myObject = new Example ();

    int population1 = 1;

    int population2 = 2;

    int population3 = 3;

    int population4 = 4;

    int max = myObject. Max (population1, population2, population3, population4);

    System. out. println (max); / / 4

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “max is a method that accepts two int arguments and returns the value of the larger one. Four int variables, population1, population2, ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers