1
我試圖創建一個程序,刪除數組中給定的字符,然後打印出新的陣列,每當我把它打印出來我得到這樣的[我奇怪的結果@ 120acab陣列式打印怪異字符
public static int[] removeVal(int[] numArray, int val)
{
int purge = 0;
int keep = 1;
int arrayVal = 0;
for (int item : numArray)
{
if(item == val)
purge = purge + 1;
else
keep = keep + 1;
}
int[] newArray = new int[keep];
for (int taco : numArray)
{
if(taco != val)
newArray[arrayVal] = taco;
arrayVal = arrayVal + 1;
}
return newArray;
}