AP Computer Science --- Haas --- ArrayForEachLoop
/**
* The for-each statement allows you to iterate through all the
* items in a collection. Is it a new feature of J2SE5.0.
*
* for (type value : container) statement
*/
import java.util.*;
public class ArrayForEachLoop {
public static void main(String args[]) {
/**
* Example 1 <<< This code is complete >>>
*/
int[] nums = {5, 1, 3, 8};
/*** prints array using for loop ***/
for (int x = 0; x < nums.length; x++)
System.out.print(nums[x] + " ");
System.out.println();
/*** prints array using the for-each loop ***/
for (int x : nums)
System.out.print(x + " ");
System.out.println();
/**
* Example 2 <<< Complete the code >>>
*/
String[] names = {"Carl","Joan","Stew","Lulu","Chet"};
/*** prints array using for loop ***/
// <<< Print out the array using for loop >>>
/*** prints array using the for-each loop ***/
// <<< Print out the array using for-each loop >>>
}
}