+ 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
5 odpowiedzi
+ 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
+ 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.
+ 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.
+ 1
Thanks a lot. So now i go practice more :)
+ 1
Will read and check later, thanks a lot :)