Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default Without using reverse method

    how can I reverse a word "beautiful" without using Reverse() method?

    I need to know because I'm going to make it as a basis for VB and C. I'm going to make a comparison. It will be my report that's why I really need to understand it.

    I checked on some sites but they are using Reverse() Method.

    Thanks a lot.
    Heart is the only broken thing that still works.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    iterate over the string from the end to the beginning and use the charAt method and add these characters to the end of a new empty string / or use a stringbuilder

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,048
    Blog Entries
    7
    Rep Power
    23

    Default

    ... or do it the recursive way:

    - if a String contains at most one character the String is its own reverse, otherwise:
    - append the first character of the String to the reverse of the rest of the Sitrng.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  4. #4
    off99555 is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default

    Here's what you want, isn't it?

    Java Code:
    String s = "some text";
    StringBuilder sb = new StringBuilder();
    for (int i = s.length() - 1; i >= 0; i--) {
        sb.append(s.charAt(i));
    }
    System.out.println(sb.toString());
    I'm a teenage Thai Java programmer who studying in secondary school.
    Practicing English in process ...

Similar Threads

  1. Reverse a string?
    By cysquatch in forum New To Java
    Replies: 15
    Last Post: 03-23-2010, 03:31 AM
  2. Replies: 0
    Last Post: 12-11-2009, 11:26 PM
  3. Reverse a string not using the substring method
    By kathyla18 in forum New To Java
    Replies: 17
    Last Post: 04-08-2009, 04:08 AM
  4. how do i reverse this method for sorting?Again!
    By PureAwesomeness in forum New To Java
    Replies: 2
    Last Post: 03-09-2009, 01:51 AM
  5. [SOLVED] how do i reverse this method for sorting?
    By PureAwesomeness in forum New To Java
    Replies: 3
    Last Post: 03-08-2009, 10:37 PM

Posting Permissions

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