gk karthayani wrote:is this wrong?
please clarify...
No it's quite clever actually. You reverse the whole string and then split it into separate words. The conventional approach probably would be to first split the string into words and then reverse each
word separately. The latter involves more work so your solution has a slight speed advantage.
The problem is that the OP most likely is supposed to come up with a more low-level algorithmic approach. It's important during education otherwise the new generation Java programmers will become "API suckers" who are totally lost when they can't find a Java library method that exactly fits the bill.