From CS160

Main: Lab14Solution

public class Lab14 
{
	public static void main(String[] args) 
	{
		int[] array1 = new int[2];
		array1[0] = 8;
		array1[1] = 42;//This was a typo
		int[] array2 = new int[2];
		array2[0] = 8;
		array2[1] = 42;

		//print the elements of the array
		for(int i = 0; i < array1.length; i++)
			System.out.println(array1[i]);
		for(int i = 0; i < array1.length; i++)
			System.out.println(array2[i]);

		//see if the arrays have the same elements:
		for(int i = 0; i < array1.length; i++)
		{
			if (array1[i] != array2[i])
			{
				System.out.println("The elements are different");
				return;
			}
		}
		System.out.println("The arrays contain the same elements");
	}
}
Retrieved from http://www.cs.colostate.edu/~asa/courses/cs160/fall08/pmwiki/pmwiki.php/Lab14Solution
Page last modified on December 04, 2008, at 03:46 PM MST