-
-
Save bytecodeman/87873214f194c548ad460861079860b6 to your computer and use it in GitHub Desktop.
Variable Length Parameters in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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