I want to make an array from something like this:
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
To this:
{6, 5, 4, 3, 2, 1, 0, 13, 12, 11, 10, 9, 8, 7, 20, 19, 18, 17, 16, 15, 14}
But I'm clueless how. I think this method can serve as a good alternative to the code I plan to do. (I'm using Dr. Java so no imported files BTW)
for an integer array called integer[]:
(for j = 0; j < 3; j++) {
(for k = 0; k = 6; k++) {
int newj = j+1;
int array = integer[k*newj];
integer [k*newj] = integer[6 - k*newj -1];
integer[6 - k*newj - 1] = array;
}
}
But this doesn't work.
Any advice? It's not part of an assignment, but it's part of an exam that will happen within a week and I want to be sure of this.
k = 6tok <= 6. Also, yourforsyntax is wrong, it should befor (j = 0; j < 3; j++), i.e.,foroutside the parens.newj, you can just havejiterate from 1 to 3 if that's what you want:for (int j = 1; j <= 3; j++).