Ask Question
9 November, 22:11

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.

+2
Answers (1)
  1. 10 November, 00:37
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers