# identical arrays program

• 11-10-2011, 08:10 AM
grcarr77
identical arrays program
I am getting this output with the code below
Enter list1: 5
2
5
6
6
1
Enter list2: 5
5
2
6
1
6
Two lists are identical

I have to press enter twice after the first number and once after each additional number. I need it to allow me to enter all six numbers then press enter for each list. and the output should look like this :

Enter list1: 5 2 5 6 6 1
Enter list2: 5 5 2 6 1 6
Two lists are identical

Code:

```package arrays; import java.util.Arrays; public class CheckArrays { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Enter list1: "); int size1 = input.nextInt(); int[] list1 = new int[size1]; for (int i = 0; i < list1.length; i++) list1[i] = input.nextInt(); System.out.print("Enter list2: "); int size2 = input.nextInt(); int[] list2 = new int[size2]; for (int i = 0; i < list2.length; i++) list2[i] = 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) { Arrays.sort(list1); Arrays.sort(list2); } else return false; for (int i = 0; i < list1.length; i++) {     if (list1[i] != list2[i]) return false; } return true;     } }```
• 11-10-2011, 09:20 AM
Mr777
Re: identical arrays program
Well, use String arrays and get the numbers with the difference value of " ".
• 11-10-2011, 11:05 PM
Junky
Re: identical arrays program
Quote:

Originally Posted by grcarr77
What do I add to the code to make the output look like the second one.

Nothing. Simply only hit enter once after the last digit is typed. So the input would be: 5space2space5space6space6space1enter