You can come very close using the code you already have, by just adding the modulo operator for the second and third lists. Adding elements "mod 1000" ensures that you have no values in the list greater than 1000. (You have to add one to the resulting values to shift the range up from 0-999 to 1-1000).
inputTenThousand2[a] = (a % 1000) + 1;
Of course, this doesn't preserve the sorted order you created originally, but once you generate these arrays, you'll notice a very clear pattern. Your array is now just the numbers 1-1000, repeated ten times. This makes picturing what the array would look like sorted very easy:
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
...
1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]
So, we can just construct that nice sorted list in the first place:
int [] inputTenThousand2 = new int[10000]; // 10000 sorted integers
for (int v = 0; v < 1000; v++) { // loop from 0 to 999
for (int i = 0; i < 10; i++) {
inputTenThousand2[(10*v) + i] = v + 1; // Set ten elements per value of the outer loop
}
}
You can then copy this list into a third list and "slightly unsort" it for your third case!
Of course, depending on what you have access to (this looks like an assignment, so maybe you don't have sorting readily available), it's likely to be easier to just create the first list as you have it already, then copy it and sort it for the second case.
Answer from Henry Keiter on Stack Overflow