// ForeachDemo.java Copyright (c) 2005 Kari Laitinen // http://www.naturalprogramming.com // 2005-04-20 File created. // 2005-04-20 Last modification. class ForeachDemo { public static void main( String[] not_in_use ) { int[] array_of_integers = { 33, 444, 55, 6, 777 } ; String[] array_of_strings = { "January", "February", "March" } ; System.out.print( "\n\n array_of_integers printed with a for loop:\n\n " ) ; for ( int integer_index = 0 ; integer_index < array_of_integers.length ; integer_index ++ ) { System.out.print( " " + array_of_integers[ integer_index ] ) ; } System.out.print( "\n\n array_of_integers printed with a foreach loop:\n\n " ) ; for ( int integer_in_array : array_of_integers ) { System.out.print( " " + integer_in_array ) ; } System.out.print( "\n\n array_of_strings printed with a for loop:\n\n " ) ; for ( int string_index = 0 ; string_index < array_of_strings.length ; string_index ++ ) { System.out.print( " " + array_of_strings[ string_index ] ) ; } System.out.print( "\n\n array_of_strings printed with a foreach loop:\n\n " ) ; for ( String string_in_array : array_of_strings ) { System.out.print( " " + string_in_array ) ; } } }