Ask Question

Assign to maxSum the max of (numA, numB) PLUS the max of (numY, numZ). Use just one statement. Hint: Call findMax () twice in an expression.

import java. util. Scanner;

public class SumOfMax {

public static double findMax (double num1, double num2) {

double maxVal = 0.0;

/ / Note: if-else statements need not be understood to

/ / complete this activity

if (num1 > num2) { / / if num1 is greater than num2,

maxVal = num1; / / then num1 is the maxVal.

}

else { / / Otherwise,

maxVal = num2; / / num2 is the maxVal.

}

return maxVal;

}

public static void main (String [] args) {

double numA = 5.0;

double numB = 10.0;

double numY = 3.0;

double numZ = 7.0;

double maxSum = 0.0;

/ * Your solution goes here * /

System. out. print ("maxSum is: " + maxSum);

return;

}

}

+4
Answers (1)
  1. 18 December, 01:13
    0
    maxSum=findMax (numA, numB) + findMax (numY, numZ);

    Explanation:

    In the above statement, a function is used twice to calculate the maximum of 2 numbers passed as parameters of type double and returns the maximum value of type double as well. As the function is static, so, there is no need to make an object of the class in which the function is made. After finding the largest of both the pairs, the values are added and printed to console.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Assign to maxSum the max of (numA, numB) PLUS the max of (numY, numZ). Use just one statement. Hint: Call findMax () twice in an ...” 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