Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. public class IdenticalArrays
  4. {
  5. public static void main(String [] Args)
  6. {
  7. Scanner input = new Scanner(System.in);
  8.  
  9.  
  10.  
  11. System.out.println("Enter list: ");
  12. String s = input.nextLine();
  13. char sizeofArray = s.charAt(0);
  14.  
  15. int size = (int)sizeofArray;
  16.  
  17. int[] firstList = new int [size];
  18. for(int i = 0; i < firstList.length; i++)
  19. {
  20. firstList[i] = s.charAt(i+1);
  21. }
  22.  
  23.  
  24.  
  25. System.out.println("Please enter list 2: ");
  26. int[] secondList = new int[size];
  27.  
  28. for (int i=0; i<10; i++)
  29. {
  30. secondList[i] = s.charAt(i+1);
  31. }
  32.  
  33.  
  34. boolean status = equals(firstList, secondList);
  35. if(status == true)
  36.  
  37.  
  38. System.out.println("The first list is: " + firstList.length + " " + firstList);
  39. System.out.println("The second list is: " + secondList.length + " " + secondList);
  40.  
  41. }
  42.  
  43. public static boolean equals(int[] list1, int[] list2)
  44. {
  45.  
  46. Arrays.sort(list1);
  47. Arrays.sort(list2);
  48.  
  49. for(int i = 0; i < list1.length && i < list2.length; i++)
  50. {
  51. if (list1[i] != list2[i])
  52. {
  53. return false;
  54. }
  55. }
  56. return true;
  57.  
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement