How to Reverse Words from a Given String Of Words

How to Reverse Words from a Given String Of Wordsfor example say "Today is wedensday" then it should meaningful Reversed and result should be "wedensday is Today"
SOURCE : WordReverseString.java

import java.util.StringTokenizer;

public class WordReverseString {

public static void main(String[] args) {

String s = "Today is wedensday";

StringBuffer sb = new StringBuffer();

StringTokenizer st = new StringTokenizer(s);
while (st.hasMoreTokens()) {

sb.insert(0, st.nextToken());
sb.insert(0, " ");
}
String sbrevrse = sb.toString();

System.out.println(sbrevrse);
}

}


INPUT

String s = "Today is wedensday";



OUTPUT

wedensday is Today







Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment