Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-10-2007, 10:27 AM
Member
 
Join Date: Jul 2007
Posts: 4
HeavyD is on a distinguished road
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 10:40 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-10-2007, 03:07 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
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:

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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 11:40 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org