import java.util.Scanner;
public class identicalArrays {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter list1: ");
int firstList1 = input.nextInt();
int[] list1 = new int[firstList1];
for (int i = 0; i < list1.length; i++) {
firstList1 = input.nextInt();
}
System.out.print("Enter list2: ");
int firstList2 = input.nextInt();
int[] list2 = new int[firstList2];
for (int j = 0; j < list2.length; j++) {
firstList2 = input.nextInt();
}
if (equal(list1, list2)) {
System.out.println("Two lists are identical");
} else {
System.out.println("Two lists are not identical");
}
}
public static boolean equal(int[] list1, int[] list2) {
if (list1.length == list2.length) {
for (int x = 0; x < list1.length; x++) {
for (int k = 0; k < list2.length; k++) {
if (list1[x] != list2[k]) {
return false;
}
}
}
return true;
} else {
return false;
}
}
}
This post has been edited by illuss: 23 April 2011 - 10:34 AM

New Topic/Question
Reply



MultiQuote





|