0

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?

8
Contributors
7
Replies
9
Views
11 Years
Discussion Span
Last Post by tknows
0

Yes, just like what iamthwee said. Loop would work. Store the name in an array variable and use looping statement to loop it backward.

0

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.

0

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.

0

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:

for(int i = s.length(); i >=0; i--){
    System.out.print(s.charAt(i);
}
System.out.println();
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.