int A = 300;
int B = 400;
int C = 1000;
int D = 500;
int []abcd = {A,B,C,D};
Arrays.sort(abcd); // the sequence of array elements will be {300, 400, 500,1000}
First of all, the variables A, B, C and D have no "location in the array". What you did was to create a blank array with 4 slots, and affect the values of those variables in position 0, 1, 2 and 3.
When you sort the array, the values (once again) get shuffled between the array's slots, but sort() doesn't know anything about the variables A, B, C and D, so their values remain unchanged. If you want those to change, you need to re-affect back the values into the variables, by using each slot's position:
A = abcd[0];
B = abcd[1];
C = abcd[2];
D = abcd[3];
What you want is a mapping from value to array location. Unless there's a way to get such a mapping out of Arrays.sort(), which I doubt (though I'm no Java expert), you'll need to generate the mapping yourself. You could do this by searching the array. It might be more efficient to implement your own sort so that you can keep track of the mapping as you sort the array.
A naive way to do it would be to go through each element of the array, checking the values as you go:
for (int i = 0; i < abcd.length; i++)
{
if (abcd[i] == A)
{
A = i+1;
}
}
// Rinse and repeat for B, C, D
If going down this approach, of course, turn it into a function that accepts the array, the value to search for, and returns its index within the array.
Are you looking for the syntax of array element access or something more complicated?
In Java,
abcd[2] = 500; abcd[3] = 1000;
will make the modification you're looking for.
just loop it to change the value :
for(int i=0;i<abcd.length;i++){
abcd[i] = i+1;
}
System.out.println(Array.toString(abcd));
Don't sort them. Put them in one array, have a second array initialized to all zeros, and count how many items are greater than or equal to each element. Then just transfer these counts back to the variables.