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?

Member Avatar for iamthwee

Yes a for loop that prints the characters in the array backwards would work.

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

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.

Hi newbies in java. May i know how to do it without using array?

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.

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();

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.