heelp java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

heelp java

static int[] analizaTablicy(int[] arr1, int[] arr2){ for (int i = 0; i < arr1.length; i++) { for (int j = 0; j < arr2.length; j++) { if (arr1[i] != arr2[j]){ } } } } this is the fragment of code in which i need write function that will be return value of arr1 that doesn't containts in arr2. Please help me to finish the code

19th Feb 2019, 10:49 PM
Kasia Herasymenko
Kasia Herasymenko - avatar
2 Answers
+ 1
Bram very nice explanation! Kasia Herasymenko I strongly suggest to try to understand Bram's directions and make code based on that understanding. Also, I am providing you here slightly different solution, and that is just because fancy output :-D https://code.sololearn.com/cA2VnX04hA86/?ref=app
20th Feb 2019, 3:00 AM
vlada
+ 2
Before the 2 forloops you have to declare a new empty array for the difference. In the 1st forloop: int different = 1 In the 2nd forloop: if (arr1[i] == arr2[j]){ different = 0 continue } After 2nd forloop, but still in the 1st forloop: if (different) { #append arr1[i] to new array } After the 2 forloops, return the array. Now the function returns an array with all elements in arr1 that are not in arr2. The different variable is only set to 0 when a element in array2 is the same. So when it isnt 0, the current element of array1 is not in array2.
19th Feb 2019, 11:46 PM
Bram