import java.util.Scanner;
public class StrictlyIdentical {
private static Scanner input;
public static void main(String[] args) {
input = new Scanner(System.in);
System.out.print("Enter 5 elements for list1:");
int[] list1 = new int[input.nextInt()];
for (int i = 0; i < list1.length; i++) {
list1[i] = input.nextInt();
}
System.out.print("Enter 5 elements for list2:");
int[] list2 = new int[input.nextInt()];
for (int i = 0; i < list2.length; i++) {
list2[i] = input.nextInt();
}
if (equals(list1, list2)) {
System.out.println("The two lists are strictly identical");
} else {
System.out.println("The two lists are not strictly identical");
}
}
public static boolean equals(int[] list1, int[] list2) {
if (list1.length != list2.length)
return false;
for (int i = 0; i < list2.length; i++) {
if (list1[i] != list2[i])
return false;
}
return true;
}
}
This is what I have. When prompted to enter list 1: I enter 1 2 3 4 5. Then when prompted to enter list 2 I enter 1 2 3 4 5. I keep getting the two lists are not strictly identical, however when all the values in the list are equal and are the same values for both lists then I get the two lists are strictly identical.