Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. public class Algorithm1{
  2. public static void main (String[] args){
  3.  
  4. int[] array1 = {1, 2, 3};
  5. int[] array2 = {1, 2, 3, 4, 5, 6};
  6. int matchCount = 0;
  7. boolean match = false;
  8.  
  9. for(int j = 0; j < array1.length;j++) {
  10. for(int i = 0; i < array2.length;i++){
  11. if(array1[j] == array2[i])
  12. matchCount++;
  13.  
  14.  
  15. }
  16. }
  17. if(matchCount >= array1.length && matchCount >= array2.length)
  18. match = true;
  19.  
  20. if(match = true){
  21. System.out.println("The data in the arrays is the same.");
  22. }
  23. else if(match = false){
  24. System.out.println("The data in the arrays is different.");
  25. }
  26. }
  27. }
  28.  
  29. if(match = true) {
  30. System.out.println("The data in the arrays is the same.");
  31. }
  32.  
  33. if(match = true){
  34. System.out.println("The data in the arrays is the same.");
  35. }
  36. else if(match = false){
  37. System.out.println("The data in the arrays is different.");
  38. }
  39.  
  40. if(match == true){
  41. System.out.println("The data in the arrays is the same.");
  42. }
  43. else if(match == false){
  44. System.out.println("The data in the arrays is different.");
  45. }
  46.  
  47. if(match){
  48. System.out.println("The data in the arrays is the same.");
  49. }
  50. else{
  51. System.out.println("The data in the arrays is different.");
  52. }
  53.  
  54. import java.io.*;
  55. import java.util.Arrays;
  56.  
  57. class Ideone
  58. {
  59. public static void main (String[] args) throws java.lang.Exception
  60. {
  61. int[] array1 = {1, 2, 3, 6, 5, 4, 3};
  62. int[] array2 = {1, 2, 3, 4, 5, 6, 4, 4,6};
  63. java.util.Arrays.sort(array1);
  64. java.util.Arrays.sort(array2);
  65. boolean match = true;
  66. int ptr1 = 0;
  67. int ptr2 = 0;
  68. while(ptr1<array1.length && ptr2<array2.length && array1[ptr1]==array2[ptr2])
  69. {
  70.  
  71. ptr1++;ptr2++;
  72. while(ptr1<array1.length && array1[ptr1]==array1[ptr1-1])
  73. {
  74. ptr1++;
  75. }
  76. while(ptr2<array2.length && array2[ptr2]==array2[ptr2-1])
  77. {
  78. ptr2++;
  79. }
  80. }
  81. if((ptr1 == array1.length) && (ptr2 == array2.length))
  82. System.out.println("The data in the arrays is the same");
  83. else
  84. System.out.println("The data in the arrays is the different");
  85. }
  86. }
  87.  
  88. public int findArray(Integer[] arg1, Integer[] arg2)
  89. {
  90. return Collections.indexOfSubList(Arrays.asList(arg1), Arrays.asList(arg2));
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement