How do I get a reverse order from the String Tokenizer?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: How do I get a reverse order from the String Tokenizer?

  1. #1
    Brad Clark Guest

    How do I get a reverse order from the String Tokenizer?


    I am working on a Java Assignment in school. We are dealing with the String
    tokenier. I need to find a command that will aloow me to tokeinze a string
    from user input and reverese the order of the words

    Any suggestion would be apprecated.

    Brad Clark

  2. #2
    Paul Clapham Guest

    Re: How do I get a reverse order from the String Tokenizer?

    Here's a hint: you won't be able to output the words in reverse order until
    you have read them all in.

    Brad Clark <Clar0135@algonquincollege.com> wrote in message
    news:396da134$1@news.devx.com...
    >
    > I am working on a Java Assignment in school. We are dealing with the

    String
    > tokenier. I need to find a command that will aloow me to tokeinze a string
    > from user input and reverese the order of the words
    >
    > Any suggestion would be apprecated.
    >
    > Brad Clark




  3. #3
    John Timney (MVP) Guest

    Re: How do I get a reverse order from the String Tokenizer?

    Here is a slightly unorthadox method to make you think about how to approach
    the solution. You can work out how to get the user input yourself.

    Regards

    John Timney (MVP)


    import java.util.*;

    public class string {
    public static void main(String args[]){

    StringBuffer myStringBuffer = new StringBuffer("which token comes first");
    StringTokenizer st = new
    StringTokenizer(myStringBuffer.reverse().toString(), " ");

    while(st.hasMoreTokens()){
    StringBuffer s= new StringBuffer(st.nextToken());
    System.out.println(s.reverse());
    }


    }

    }




    Paul Clapham <pclapham@core-mark.com> wrote in message
    news:396dd89a@news.devx.com...
    > Here's a hint: you won't be able to output the words in reverse order

    until
    > you have read them all in.
    >
    > Brad Clark <Clar0135@algonquincollege.com> wrote in message
    > news:396da134$1@news.devx.com...
    > >
    > > I am working on a Java Assignment in school. We are dealing with the

    > String
    > > tokenier. I need to find a command that will aloow me to tokeinze a

    string
    > > from user input and reverese the order of the words
    > >
    > > Any suggestion would be apprecated.
    > >
    > > Brad Clark

    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center