200k views
0 votes
Import java.util.scanner; public class sumofmax { public double findmax(double num1, double num2) { double maxval; // 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;

1 Answer

3 votes

Here you go,


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 */

maxSum = findMax(numA, numB); // first call of findMax

maxSum = maxSum + findMax(numY, numZ); // second call

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

return;

}

}

/*

Output:

maxSum is: 17.0

*/

User JPot
by
5.2k points