Results 1 to 2 of 2

Thread: HElp

  1. #1
    HeavyD is offline Member
    Join Date
    Jul 2007
    Posts
    4
    Rep Power
    0

    Default How do i get user input and then reverse what the user typed

    Hey Guys,

    How do i get user input and then reverse what the user typed.

    e.g
    Hello to olleh
    Last edited by JavaBean; 07-10-2007 at 08:40 AM.

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    Here is how you can get user input from console:

    Java Tips - How to read input from console

    And for reversing your string, you have two choices:

    1. You can use reverse method of StringBuffer:

    Java Code:
    StringBuffer b = new StringBuffer("Hello").reverse();
    2. Create a new string based on characters in the input string

    For this one, you will again have a string buffer and append to it the characters of your String one by one. To do that in reverse order, you will create a loop which starts from the length of your string to 0. You will get character of the string in that position with charAt(int i) function of String and append it to your string buffer.

Posting Permissions

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