Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. package pgdp.arrays;
  2.  
  3. public class GamesWithArrays {
  4.  
  5. public static int[] otherSort(int[] arr, int[] arr2) {
  6. // TODO
  7. int result[] = new int[arr.length];
  8. int resultindex = 0;
  9.  
  10. for(int i = 0; i < arr.length; i++)
  11. {
  12. result[resultindex] = arr2[i];
  13. int temp = result[resultindex];
  14. boolean already = false;
  15. int countersame = 0;
  16. for(int j = 0; j < resultindex; j++)
  17. {
  18. if(result[j] == result[resultindex])
  19. {
  20. already = true;
  21. }
  22. }
  23. if(already == false)
  24. {
  25. for(int j = 0; j < arr.length; j++)
  26. {
  27. if(arr[j] == temp)
  28. {
  29. countersame++;
  30. }
  31. }
  32. for(int j = 0; j < countersame - 1; j++)
  33. {
  34. resultindex++;
  35. result[resultindex] = arr2[i];
  36. }
  37. }
  38. resultindex++;
  39. }
  40.  
  41. if(arr.length > arr2.length)
  42. {
  43. for(int i = 0; i < arr.length; i++)
  44. {
  45. boolean contains = false;
  46. for(int j = 0; j < result.length; j++)
  47. {
  48. if(result[j] == arr[i])
  49. {
  50. contains = true;
  51. }
  52. }
  53. if(contains == false)
  54. {
  55. result[resultindex] = arr[i];
  56. resultindex++;
  57. }
  58. }
  59. }
  60. return result;
  61. }
  62.  
  63. public static int[] fairFriends(int[] arr, int[] arr2) {
  64. // TODO
  65. return new int[]{};
  66. }
  67.  
  68. public static boolean alpen(int[] arr) {
  69. // TODO
  70. return true;
  71. }
  72.  
  73. public static int[] plankton(int[] arr) {
  74. // TODO
  75. return new int[]{};
  76. }
  77.  
  78. public static int pinguinFreunde(int[] arr) {
  79. // TODO
  80. return 0;
  81. }
  82.  
  83. public static void main(String[] args)
  84. {
  85. int arr1 [] = {2,3,1,3,2,4,6,7,9,2,19};
  86. int arr2 [] = {2,1,4,3,9,6};
  87. int result[] = otherSort(arr1, arr2);
  88.  
  89. for(int i = 0; i < result.length; i++)
  90. {
  91. System.out.println(result[i]);
  92. }
  93. return;
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement