/*Reverse the given string word wise. That is, the last word in given string should come at 1st place, last second word at 2nd place and so on. Individual words should remain as it is.
// 2 pointer pointing at the last character of the String
inti = str.length() - 1/*to traverse the whole string in reverse order*/, j = str.length() - 1/*to mark the position if the first pointer i hits a space*/;
for (; i >= 0; i--) {
if (str.charAt(i) == ' ') {
StringreverseWord = "";
/*Copying the character to answer string*/
for (intk = i + 1; k <= j; k++) {
reverseWord += str.charAt(k);
}
answer += reverseWord + " ";
/*2nd pointer will be assigned to the next limit for till which the character in answer string will be copied*/
j = i - 1;
}
}
/*handling the last word case because it don't have any space*/