Greatest element of a list: Difference between revisions

Content added Content deleted
(→‎{{header|Vim Script}}: Fix indentation (tabs → spaces))
Line 2,423: Line 2,423:


=={{header|Java}}==
=={{header|Java}}==
<syntaxhighlight lang="java">
int max(int[] values) {
int max = values[0];
for (int value : values)
if (max < value) max = value;
return max;
}
</syntaxhighlight>
<br />
The first function works with arrays of floats. Replace with arrays of double, int, or other primitive data type.
The first function works with arrays of floats. Replace with arrays of double, int, or other primitive data type.
<syntaxhighlight lang="java">public static float max(float[] values) throws NoSuchElementException {
<syntaxhighlight lang="java">public static float max(float[] values) throws NoSuchElementException {