001package edu.pdx.cs410J.j2se15; 002 003import java.util.*; 004 005/** 006 * Demonstrates J2SE's "enhanced for loop" functionality. 007 * 008 * @author David Whitlock 009 * @version $Revision: 1.1 $ 010 * @since Summer 2004 011 */ 012public class EnhancedForLoop { 013 014 /** 015 * Sorts the command line arguments and prints their sum. 016 */ 017 public static void main(String[] args) { 018 int sum = 0; 019 for (String arg : args) { 020 sum += Integer.parseInt(arg); 021 } 022 023 System.out.println("Sum is " + sum); 024 System.out.print("Sorted arguments: "); 025 026 SortedSet set = new TreeSet(Arrays.asList(args)); 027 for (Object o : set) { 028 System.out.print(o + " "); 029 } 030 031 System.out.println(""); 032 } 033 034}