001package edu.pdx.cs410J.datesAndText; 002 003/** 004 * Demonstrates variable-length method arguments in J2SE 1.5. 005 * 006 * @author David Whitlock 007 * @version $Revision: 1.1 $ 008 * @since Summer 2004 009 */ 010public class VarArgs { 011 012 /** 013 * Prints the sum of a variable number of <code>int</code>s 014 */ 015 private static void printSum(String header, int... ints) { 016 int sum = 0; 017 for (int i : ints) { 018 sum += i; 019 } 020 021 System.out.print(header); 022 System.out.println(sum); 023 } 024 025 /** 026 * Prints the sum of a bunch of numbers 027 */ 028 public static void main(String[] args) { 029 printSum("1+2+3 = ", 1, 2, 3); 030 printSum("1+2+3+4+5 = ", 1, 2, 3, 4, 5); 031 printSum("2+4+6+8 = ", 2, 4, 6, 8); 032 } 033 034}