You have converted the C code that you found to Java. But the C code is the solution to a different question. Read your question again and look at the requirements:
For each i where 1 ≤ i ≤ |s|:
Append s[i-1] to the end of b.
So you need a loop tht iterates i from 1 to n-1, and move the characters as specified.
So work on that and print the result.
When that is working correctly go to the next step:
Reverse the string b.
And finally when both of the above are working implement the first part:
Before creating b, reorder s to produce the b that is the lexicographically maximum possible.