View Single Post
Old 02-09-07, 12:11 PM   #3
Marvel_us's Avatar
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
Default Re: Java Help: Reversing Letters in a String

Originally Posted by superklye
Could you perhaps break the string down into characters and put them into an array in their correct order then make a for loop the traverses the array in reverse?
That's kind of what I'm trying to do now.

Here's an example of how I did the other reverse one. In the real program the user enters the message to be encrypted but this gives you a general idea of it.

Maybe if I could do something like an if statement that executes when the current char is an empty space then reverse that, add it, and move on to the next char etc. What would be the best way to compare char to an empty space though?

StringBuilder text1 = new StringBuilder() ;

String word = "the quick brown fox" ;

for (int i = 0; i < word.length() ; i++)
char ch = word.charAt(i);

text1 = text1.reverse();
Main Rig
Intel Q6600 QUAD|| Gigabyte P35-DS3L ||XFX 7900GTX|| G.Skill 6GB PC2-6400 || OCZ Agility 60GB SSD || WD 320GB + WD Green 1TB HDD || Samsung 20" LCD || CoolMax 650W PSU ||

60gb PS3 Owner
PSNid: Marvel_us
Marvel_us is offline   Reply With Quote