【发布时间】:2021-03-20 13:26:51
【问题描述】:
我需要做的是在方法之前的 cmets 中。 A 包含一个用户输入的 10 元素长数组:
//Reverses the contents of the array. The array remains unchanged
//It prints the reversed array to the screen
static void reverseArray(int [] A)
{
int[] tempArray = new int[10];
for(int i = A.length-1; i >= 0; i--)
{
//Supposed to copy what's in reversed array A to tempArray
tempArray[i] = A[i];
}
printArray(tempArray); //Prints the updated array to the screen
}
我想要它做的是从 A 的最后一个元素倒数到第一个元素,然后将其复制到 tempArray。但现在它只打印用户输入的数组。我知道我需要 2 个整数来跟踪增加和减少的内容,但我不知道如何实现它们。
【问题讨论】:
-
想想吧。输入数组的索引
0处的项目必须位于输出数组的last 索引(此处为索引9)。然后继续以下索引。 -
ArrayUtils.reverse(int[] 数组)