Results 1 to 3 of 3

Thread: Program to reverse the order of words in a string

  1. #1
    EvansMitchell is offline Senior Member
    Join Date
    Dec 2009
    Posts
    227
    Rep Power
    3

    Default Program to reverse the order of words in a string

    Hi. I am new in programming world. Currently I am learning different programming language. I want code for reverse the order of words in a string. I tried different code but none of them worked out for me. If you have any code then let me know that. Thanks in advanced.

  2. #2
    RogersNguyen is offline Senior Member
    Join Date
    Dec 2009
    Posts
    227
    Rep Power
    3

    Default

    Program to reverse the order of words in a string:

    Code:
    import java.io.*;
    import java.lang.*;
    
    public class StringReverse
    {
        public static void main(String[] args)throws Exception
        {
            String words = "hi frends........ welcome to my  
    world";
            
            
            String reverse = new StringBuffer(words).reverse
    ().toString();
            
            
            System.out.println("Normal : " + words);
          
            System.out.println("Reverse: " + reverse);
        }
    }
    **)
    I have tried the given code but it didn’t solve my problem. Please try to provide some other solution.

  3. #3
    MorganCooper is offline Senior Member
    Join Date
    Dec 2009
    Posts
    233
    Rep Power
    3

    Default

    Code:
    import org.apache.commons.lang.StringUtils;
     
    public class StringReverseUsingStringUtils 
    {    
        public static void main(String[] args)
        {
        String string = "Hi, where r u?";         
        String reverse = StringUtils.reverse(string);
        String delimitedReverse = StringUtils.
    reverseDelimited(string, ' ');               
        System.out.println("nThe original String: " + string);
        System.out.println("The reversed string: " + reverse);
        System.out.println("The delimited Reverse string: " 
    + delimitedReverse);
        }
    }

Similar Threads

  1. C code for reverse the order of words in a string
    By HallMiller in forum Programming
    Replies: 2
    Last Post: 07-28-2010, 04:18 PM
  2. I am going reverse to XP from Vista?
    By AndersonDiaz in forum Windows XP
    Replies: 2
    Last Post: 05-24-2010, 01:31 PM
  3. Replies: 1
    Last Post: 05-03-2010, 01:37 PM
  4. How to reverse the order
    By PetersonClark in forum Programming
    Replies: 1
    Last Post: 02-16-2010, 05:57 PM
  5. C program to reverse a number
    By Millerjames in forum Programming
    Replies: 1
    Last Post: 01-13-2010, 05:42 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48