|
CS160 Class Wiki Instructors |
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");
}
}
|