0

java help

the code compare two arr and return new arr with value of arr1 that doesn't contains in arr2 static int[] analizaTablicy(int[] arr1, int[] arr2){ int dif[] = new int[arr1.length]; for (int i = 0; i < arr1.length; i++) { int different = 1; for (int j = 0; j < arr2.length; j++) { if (arr1[i] == arr2[j]){ different = 0; continue; } } if (different==1){ dif[i] = arr1[i]; } } return dif; } how to modify this code if i need return not like this [0,0,0,2,3,0], but like this [2,3].

20th Feb 2019, 10:06 PM
Kasia Herasymenko
Kasia Herasymenko - avatar
1 Answer
0
I am trying like this : static int[] analizaTablicy(int[] arr1, int[] arr2){ int dif[] = new int[arr1.length]; int count = 0; for (int i = 0; i < arr1.length; i++) { int different = 1; for (int j = 0; j < arr2.length; j++) { if (arr1[i] == arr2[j]){ different = 0; continue; } } if (different==1){ dif[count] = arr1[i]; count++; } } int [] result = new int[count]; for (int i = 0; i<count; i++){ result[i]=dif[i]; } return result; } but maybe is the shortest and better way to solve the task
20th Feb 2019, 10:31 PM
Kasia Herasymenko
Kasia Herasymenko - avatar