How do I delete the integer at the given index and how do I compress myInts
?
This is what I got but I keep getting an error.
public void deleteInt(int index) {
int[] newInts = Arrays.copyOf(myInts, myInts.length);
if (myInts[index] != 0) {
myInts[index] = 0;
for (int i : myInts) {
if (myInts[i] != 0) {
newInts[i] = myInts[i];
}
}
}
myInts = newInts;
currentInt++;
}
This is the error I get:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 11
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…