Program to reverse every word in a String using methods
public class Example
{
public void reverseWordInMyString(String str)
{
/* The split() method of String class splits
* a string in several strings based on the
* delimiter passed as an argument to it
*/
String[] words = [Link](" ");
String reversedString = "";
for (int i = 0; i < [Link]; i++)
{
String word = words[i];
String reverseWord = "";
for (int j = [Link]()-1; j >= 0; j--)
{
/* The charAt() function returns the character
* at the given position in a string
*/
reverseWord = reverseWord + [Link](j);
}
reversedString = reversedString + reverseWord + " ";
}
[Link](str);
[Link](reversedString);
}
public static void main(String[] args)
{
Example obj = new Example();
[Link]("Welcome to BeginnersBook");
[Link]("This is an easy Java Program");
}
}
___