0

Hey, i am practicing in this book sample, it says i can rewrite my code for determining the highest value in my 3 input. the commented part is working perfectly (Line 19, 26), it can return the highest value...

but when i try to rewrite it using the Math.max method, it only return the second highest number, not the highest on the 3..=/

the logic is right? right?

the inner max is evaluated first then the result will be compared to the n1 variable...

return Math.max(n1,Math.max(n2,n3));

```
import java.util.Scanner;
public class MaximumFinder
{
public void determineMaximumValue()
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter 3 float variable in spaces: ");
double num1 = scan.nextDouble();
double num2 = scan.nextDouble();
double num3 = scan.nextDouble();
System.out.println("The maximum value is: " + maximum(num1,num2,num2));
}
public double maximum(double n1, double n2, double n3)
{
/* double maxValue = n1;
if(n2 > maxValue)
maxValue = n2;
if(n3 > maxValue)
maxValue = n3;
return maxValue; */
return Math.max(n1,Math.max(n2,n3));
}
public static void main(String args[])
{
MaximumFinder mf = new MaximumFinder();
mf.determineMaximumValue();
}
}
```

uhm..sorry for the trouble, but can someone tell what's wrong? =/