Name Backwards Algorithm

Reply

Join Date: Sep 2006
Posts: 8
Reputation: Klitzy is an unknown quantity at this point 
Solved Threads: 0
Klitzy Klitzy is offline Offline
Newbie Poster

Name Backwards Algorithm

 
0
  #1
Sep 18th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Name Backwards Algorithm

 
0
  #2
Sep 18th, 2006
Yes a for loop that prints the characters in the array backwards would work.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 84
Reputation: rinoa04 is on a distinguished road 
Solved Threads: 4
rinoa04's Avatar
rinoa04 rinoa04 is offline Offline
Junior Poster in Training

Re: Name Backwards Algorithm

 
0
  #3
Sep 19th, 2006
Yes, just like what iamthwee said. Loop would work. Store the name in an array variable and use looping statement to loop it backward.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Name Backwards Algorithm

 
0
  #4
Sep 19th, 2006
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 4
Reputation: comtech is an unknown quantity at this point 
Solved Threads: 0
comtech comtech is offline Offline
Newbie Poster

Re: Name Backwards Algorithm

 
0
  #5
Sep 20th, 2006
Hi newbies in java. May i know how to do it without using array?
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,366
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Name Backwards Algorithm

 
0
  #6
Sep 20th, 2006
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: Name Backwards Algorithm

 
0
  #7
Sep 20th, 2006
Originally Posted by comtech View Post
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:
  1. for(int i = s.length(); i >=0; i--){
  2. System.out.print(s.charAt(i);
  3. }
  4. System.out.println();
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 1
Reputation: tknows is an unknown quantity at this point 
Solved Threads: 0
tknows's Avatar
tknows tknows is offline Offline
Newbie Poster

Re: Name Backwards Algorithm

 
0
  #8
Sep 20th, 2006
Originally Posted by Klitzy View 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?
: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.
knowledge is what I need
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC