+ 2

Java Math.max always compares 2 arguments or it can have more then 2. Check my 1st code with Java i made a program and need help

https://code.sololearn.com/cvlWXmyu4JDj/?ref=app

4th Oct 2018, 7:36 AM
Mateusz Legend
Mateusz Legend - avatar
5 ответов
+ 3
Math.max accepts only 2 elements https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html If you are use int[], you can check which one is Max using the loop int max = Integer.MIN_VALUE; for(int i : arrayOfNumbers) { if(max < i) { max = i } } You can use the Arrays class to sort out numbers, and print the last number of tables https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html
4th Oct 2018, 7:50 AM
Daniel (kabura)
Daniel (kabura) - avatar
+ 2
so what i have done in this code is acceptable :p i know it can be done easier with loops when there are a lot of numbers from which we choose max.
4th Oct 2018, 7:53 AM
Mateusz Legend
Mateusz Legend - avatar
+ 1
I don't know if Java has a fancier max() that takes multiple inputs, but I think your strategy for finding the maximum of three numbers is accurate. Well done! 👍 And yes, for an arbitrary (but finite) collection of numbers, you'd need a loop.
4th Oct 2018, 8:00 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
Thanks a lot. So now i go practice more :)
4th Oct 2018, 8:02 AM
Mateusz Legend
Mateusz Legend - avatar
+ 1
Will read and check later, thanks a lot :)
4th Oct 2018, 8:37 AM
Mateusz Legend
Mateusz Legend - avatar