Instantly share code, notes, and snippets.

Embed
What would you like to do?
Variable Length Parameters in Java
public class VariableLengthParameters {
private static int maximum(int first, int... additional) {
int max = first;
for (int i = 0; i < additional.length; i++)
if (additional[i] > max)
max = additional[i];
return max;
}
public static void main(String[] args) {
int max = maximum(10, 4, 55, -3, 454, 23, 66);
System.out.println(max);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment