Ask Question
4 March, 14:16

Write the definitions for three functions named max. Each receives two parameters, of the same type, and returns the larger of the two values. Define one of these functions to apply to type double, another to type int and a third to type char.

+2
Answers (1)
  1. 4 March, 17:07
    0
    public double max (double m, double n)

    {

    if (m>=n)

    return m;

    else

    return n;

    }

    public int max (int m, int n)

    {

    if (m>=n)

    return m;

    else

    return n;

    }

    public char max (char m, char n)

    {

    if (m>=n)

    return m;

    else

    return n;

    }

    Explanation:

    In each of the three methods declarations (Java) above, we are comparing two variables. m and n. The question did not specify what should happen when both variables are the same (i. e. m = = n). We make an assumption and set the condition to be if (m>=n) m should be returned as the greater.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write the definitions for three functions named max. Each receives two parameters, of the same type, and returns the larger of the two ...” 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