Javatpoint Logo

reverseWords

By: naveen*** On: Wed Jun 28 17:54:58 IST 2017     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
write method public static String reverseWords(String s)
Assume that the parameter String can only contain spaces and alphanumeric characters.
Please implement this method to reverse each word in the original String while maintaining the word order.


For example: parameter: "Hello world", result: "olleH dlrow"
Up0Down

 
public class ReverseEachWord
{
static void reverseEachWordOfString(String inputString)
{
String[] words = inputString.split(" ");

String reverseString = "";

for (int i = 0; i < words.length; i++)
{
String word = words[i];

String reverseWord = "";

for (int j = word.length()-1; j >= 0; j--)
{
reverseWord = reverseWord + word.charAt(j);
}

reverseString = reverseString + reverseWord + " ";
}

System.out.println(inputString);

System.out.println(reverseString);

System.out.println("-------------------------");
}

public static void main(String[] args)
{
reverseEachWordOfString("Java Concept Of The Day");
}
}
Image Created0Down

By: [email protected] On: Fri Jun 30 13:02:04 IST 2017 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No
 
its very big process we can make it very easy .. there r two way first one by default method and second one is by using looping Image Created0Down

By: [email protected] On: Tue Aug 08 15:44:54 IST 2017 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No