Results 1 to 2 of 2
  1. #1
    jean28 is offline Member
    Join Date
    Aug 2012
    Rep Power

    Default Reversing a string?

    Let's say I have a simple string such as "Hello World" and I wanted to print it in reversed order(i.e. "dlroW olleH"). How do I do it? Do I need to store it into an array and reverse the array with a for? How do I do that?

    Thanks a lot.

  2. #2
    Darkzombies is offline Senior Member
    Join Date
    Nov 2012
    Rep Power

    Default Re: Reversing a string?

    You can make a String array with the letters for "Hello World" and have a for loop go through and print it backwards.

    Java Code:
    public class Puzzle 
    	private static String[] s = {"h","e","l","l","o"," ","W","o","r","l","d"};
        public static void main(String[] args) 
        	for(int x = s.length - 1; x > -1; x--){
    I can imagine there is a way to have just two words and seperate them into the chars they're composed of, but I sure don't know how to. :P
    Last edited by Darkzombies; 11-29-2012 at 04:00 AM.

Similar Threads

  1. Replies: 7
    Last Post: 07-19-2012, 04:45 PM
  2. reversing words of a string using stacks
    By mamoonrizwan in forum New To Java
    Replies: 1
    Last Post: 11-15-2011, 08:55 PM
  3. Reversing the String
    By Inaam in forum New To Java
    Replies: 1
    Last Post: 03-30-2009, 08:35 PM
  4. Reversing String
    By mew in forum New To Java
    Replies: 4
    Last Post: 12-02-2007, 09:42 PM
  5. reversing a string
    By toad in forum New To Java
    Replies: 5
    Last Post: 11-07-2007, 09:13 AM

Posting Permissions

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