Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: How to reverse the words in a string

Java: How to reverse the words in a string
{filelink=12230}

import java.util.Stack;
import java.util.StringTokenizer;
public class Word_Inverse
{
  public static void main (String[] args)
  	{
	String str = "Welcom to tubedir.com";
	Stack  stack = new Stack();
	StringTokenizer strTok = new StringTokenizer(str);
	while(strTok.hasMoreTokens())
	{
    stack.push(strTok.nextElement());
	}
	StringBuilder str_reverse = new StringBuilder();
	while(!stack.empty())
		{
    str_reverse.append(stack.pop());
    str_reverse.append(" ");
		}
System.out.println("original string: " + str);
System.out.println("reversed string: " + str_reverse);
    }  
}

Users who found this page were searching for:

  • from BigDecimal to words
  • program on factorial in perl
  • how to calculate factorial in perl
  • subroutine to generate factorial in perl
  • 24h format -12 -am. -pm. -dst 24 format
  • calculate the difference of days between 2 dates in perl
  • perl print line count
  • how to index the key value pair python
  • how to reverse a word in java
  • python how to read bin file and print into structure

No comments yet.

Leave a Comment