Ask Question

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.

+5
Answers (1)
  1. 5 September, 22:03
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers