943,946 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3663
  • Java RSS
Sep 18th, 2006
0

Name Backwards Algorithm

Expand Post »
Hi guys, back again...You guys were very helpful before and I ended up approaching it a totally different way. I used the mathematical way which is hard to explain but well...it worked so thanks.

Now I am having a problem constructing a program that prompts the user for a name and then displays it backwards. In this, I am excluding spaces so basically....john would be nhoj.

I know I am going to use toCharArray etc...But am i just going to use a for that decreases?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Klitzy is offline Offline
8 posts
since Sep 2006
Sep 18th, 2006
0

Re: Name Backwards Algorithm

Yes a for loop that prints the characters in the array backwards would work.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Sep 19th, 2006
0

Re: Name Backwards Algorithm

Yes, just like what iamthwee said. Loop would work. Store the name in an array variable and use looping statement to loop it backward.
Reputation Points: 52
Solved Threads: 4
Junior Poster in Training
rinoa04 is offline Offline
84 posts
since Sep 2006
Sep 19th, 2006
0

Re: Name Backwards Algorithm

why so hard? There's a method that will let you reverse a string using a single method call

Not going to tell you where to find it, it should be easy if you have the API docs at hand.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Sep 20th, 2006
0

Re: Name Backwards Algorithm

Hi newbies in java. May i know how to do it without using array?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
comtech is offline Offline
4 posts
since Sep 2006
Sep 20th, 2006
0

Re: Name Backwards Algorithm

Did you not read jwenting's reply directly above yours? Look in the API for a single method call to reverse a String. I will give a small hint, the class is not String but does begin with it.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Sep 20th, 2006
0

Re: Name Backwards Algorithm

Click to Expand / Collapse  Quote originally posted by comtech ...
Hi newbies in java. May i know how to do it without using array?
There is a string method charAt that you can use to do it without arrays.
So:
Java Syntax (Toggle Plain Text)
  1. for(int i = s.length(); i >=0; i--){
  2. System.out.print(s.charAt(i);
  3. }
  4. System.out.println();
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
Sep 20th, 2006
0

Re: Name Backwards Algorithm

Click to Expand / Collapse  Quote originally posted by Klitzy ...
Hi guys, back again...You guys were very helpful before and I ended up approaching it a totally different way. I used the mathematical way which is hard to explain but well...it worked so thanks.

Now I am having a problem constructing a program that prompts the user for a name and then displays it backwards. In this, I am excluding spaces so basically....john would be nhoj.

I know I am going to use toCharArray etc...But am i just going to use a for that decreases?
:mrgreen: If you do a count, you can then print each letter starting from the very last number in your count until your count is 0.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tknows is offline Offline
1 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: validations
Next Thread in Java Forum Timeline: Java Client/Server





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC