#Help!
16 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @fringe shuttle! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
@old notch
please do not ping people who are not actively helping you, for help
please do not spoonfeed
just like before, first figure out how many elements you need in each resulting array
loop with 2 separate variables to create the new array
Do not copy
Please send your solution
Deleted
for (int i = 0; i < array.length; i++) {
int elemsFound = 0;
for (int j = 0; j < array[i].length; j++) {
if (array[i][j] == elem) {
elemsFound++;
}
}
if (elemsFound == 0) {
continue;
}
int[] newRow = new int[array[i].length + elemsFound * (newElem.length - 1)];
int k = 0;
int l = 0;
for (int j = 0; j < array[i].length; j++) {
if (array[i][j] == elem) {
for (int m = 0; m < newElem.length; m++) {
newRow[k] = newElem[m];
k++;
}
l++;
} else {
newRow[k] = array[i][j];
k++;
}
}
array[i] = newRow;
}
return array;
}```
i completely rewrote it
@lyric sun how did u fix my old code?
my old code was very messy to me and it was hard to understand
Please close the issue/post