Arrays 数组的程序跟踪?
我正在跟踪这个程序,但似乎无法获取它。有人能解释一下吗Arrays 数组的程序跟踪?,arrays,Arrays,我正在跟踪这个程序,但似乎无法获取它。有人能解释一下吗 Question 5. Consider the following code fragment: int [ ] x = {0, 1, 2, 3}; int temp; int i = 0; int j = x.length – 1; while( i < j ){ temp = x[i]; x[i] = x[j]; x[j] = 2 * temp;
Question 5.
Consider the following code fragment:
int [ ] x = {0, 1, 2, 3};
int temp;
int i = 0;
int j = x.length – 1;
while( i < j ){
temp = x[i];
x[i] = x[j];
x[j] = 2 * temp;
i++;
j--;
}
After this code is executed, array “x” contains the values:
a) {3, 2, 2, 0}
b) {0, 1, 2, 3}
c) {3, 2, 1, 0}
d) {0, 2, 4, 6}
e) {6, 4, 2, 0}
Question 7.
Consider the following code fragment:
int[ ] array1 = {2, 4, 1, 3};
int[ ] array2 = {0, 0, 0, 0};
int a2 = 0;
for(int a1 = 1; a1<array1.length; ++a1)
{
if( array1[a1] >= 2)
{
array2[a2] = array1[a1];
++a2;
}
}
a) {4, 3, 0, 0}
b) {4, 1, 3, 0}
c) {2, 4, 3, 0}
d) {2, 4, 1. 3}