solution to question, that how to reverse the string from any point, in java

To print any type of string in this order
example " My Name Is"
output should be in this format " yM emaN sI"
every word in the string has to be reversed individually.

According to me, if you a reversing a string from a certain point, you could assign it to a char[] array and run two decrementing loops. If you want to reverse each word separately, read from the console using scanner.next() and reverse individual word using char[] array.
You could also refer to this link: Reverse a string in Java - Stack Overflow

1 Like

Well, if you are using java

If you are sure that words are broken by only having space between them, you can use following idea…

String s = your string

String[] ar = s.split (" ");

String out = “”;

For(int i=0; i < ar.length; i++){

Out += new StringBuilder (ar [i]).reverse ().toString () + " ";

}

System.out.printlnt (out);

In C++, you can add each word to a vector and then run a loop on teachhis vector, running a backward loop on each word and appending to output string…

Please UPVOTE and Accept this answer if you find this helpful…

Please accept the answer, if it was helpful!