Answer the question
In order to leave comments, you need to log in
How to handle more than two numbers in Math.max method?
I started learning Java, Horstmann's assignment requires using the Math.max method to determine the largest of the 3 entered numbers, but as far as I understand, the method can only compare 2 numbers, or have I misunderstood something?
Answer the question
In order to leave comments, you need to log in
Yes, you are right, but it takes two arguments, but the task is done differently. int max = Math.max(Math.max(a,b),c);
those. there is a maximum of two numbers, and then we find the largest among the maximum and the third number.
1st option
TreeSet<Double> doubles = new TreeSet<>(Arrays.asList(1.34, 2.34, 3.34, 1.74, 0.34));
System.out.println(doubles.last());
double max = NumberUtils.max(1.34, 2.34, 3.34, 1.74, 0.34);
System.out.println(max);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question