for (int x = 0; x < arr.length - 1; x++)
{
for (int y = 0; y < 3; y++)
{
pos++;
System.out.println("pos+++" + pos);//这里我多加了一条输出语句,方便你看pos的数值变化,如再看明白,我不知如何了
if (pos == arr.length)
pos = 0;
while (arr[pos] == 0)
{
pos++;
if (pos == arr.length)
pos = 0;
}
}
arr[pos] = 0;
System.out.println(arr[pos]);
}
for (int x = 0; x < arr.length; x++)
{
//if (arr[x] != 0)
//{
System.out.println(arr[x] + "+++++++");
//break;
//}
}
}
}
这道题的最终结果是:int型数组中只留下一个元素保留原来数值。