VarArgs2.java
Select all
/* VarArgs2.java CIS 260 2/16/2005 David Klick Demonstrates the use of the new Java 1.5 variable argument feature, syntax, and usage. */ import java.util.*; public class VarArgs2 { public static void main(String[] args) { int[] n = { 3, 5, 18, 2, -9, 14 }; System.out.println("Max of " + Arrays.toString(n) + " is " + max(n)); } static int max(int... arr) { if (arr.length == 0) throw new IllegalArgumentException("Zero length array not valid"); int max = arr[0]; for (int i : arr) if (max