Thursday, July 18, 2019

Java Program 5: How to reverse given string and each word of it?

Let us understand the problem with an example, suppose "Learn Core Java" is the given string then the expected output should be "nraeL eroC avaJ". We just reverse each word and print the string.



Let us implement the logic step by step:

Step 1: Read the string and split the words using white-space as delimiter. This will return a array of Strings

Step 2: Now write a method that reverses the given word and returns it. In our case reverseWord() method.

Step 3: Use StringBuilder to construct a new string using reversed words. Each reversed word will be appended with a white-space to the string builder except last word.

Checkout the below program

Hope you understood the how to solve the above problem. Thanks for reading.

Happy Testing. Happy Learning.

3 comments:

  1. Excellent post, thanks for this. I gathered lots of information from this and I am happy about it. Do share more updates.thanks for your information really good and very nice web design company in velachery

    ReplyDelete
  2. Nice post. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated posts…
    Informatica online Training
    Data Science Online Training

    ReplyDelete
  3. frases de buenos dias Very informative information on your site here. I like this post because we can get some useful information from your blog. I expect more post from you

    ReplyDelete

DevOps 01: What is DevOps and How it benefits organizations?

DevOps is a culture in an organization, where the development team and operations team help each other by sharing information, process and t...