Advertisement
Guest User

Untitled

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