想改变数组顺序怎么写
{ 5, 3, 6, 1, 0, 2, 4 } 变成 { 6, 1, 0, 2, 4, 5, 3 } ?我写的是
public static int[] Index() {
int a[] = { 5, 3, 6, 1, 0, 2, 4 };
return a;
}
public static int[] NewIndex() {
int a[] = Index();
int start = 6;
int num = 0;
int b[] = a;
for (int i = 0; i < a.length; i++) {
if (a[i] == start) {
num = i;
}
b[i] = a[(i - num + 7) % 7];
}
return b;
}
结果不对 错在哪里?
[此贴子已经被作者于2023-7-3 20:08编辑过]