|
|
#1 | |
|
FOOL!
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
|
I need to reverse letters in each string in a program that encrypts/decrypts messages in 3 ways. I've done two but can't figure out the last one. I'll just show you guys an example of what I need to do.
Quote:
Any suggestions? If anyone still isn't clear on what I need to do please let me know.
__________________
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 |
|
|
|
|
|
|
#2 | |
|
Join Date: Jul 2004
Location: MKE
Posts: 13,629
|
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?
|
|
|
|
|
|
|
#3 | ||
|
FOOL!
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
|
Quote:
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? Quote:
__________________
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 |
||
|
|
|
|
|
#4 | |
|
xeroyphyte
Join Date: Mar 2004
Posts: 1,271
|
sounds to me like you are storing the string as one long continuous entity. what you need to do is parse the string based on ascii value 32 (space) or value 10 (new line) or value 0 (null - end of string). once you parse each string into the subsequent substrings, you can reverse the substrings and print them back adding the spaces between them.
in you for loop test to make sure the char isn't one of these values, for (looping){ building word; if (space/NL/LF/null){ reverse string print string (to file or screen) string = '\0' (clear string) } }//continue working through entire string.
__________________
HT: 360 -- Sony60A3000 -- Onkyo SR605 --> Polk cs2, monitor 60s and monitor 40s w/ Bic F12 sub -- PS3 XBL:Mr X3r0 -- PSN:Mr_X3r0 Rig- Asus P6X58D Premium - intel i7 920 @3.6 - EVGA GTX570 - Corsair HX1000 - Prolimatech Mega Shadow - WD640 - COOLER MASTER ATCS 840 - OCZ Gold 6GB DDR3 1600* |
|
|
|
|
|
|
#5 |
|
FOOL!
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
|
Thanks, question though.
For char you have to use .compareTo() right? So it would be ch.compareTo(space)?
__________________
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 |
|
|
|
|
|
#6 | |
|
xeroyphyte
Join Date: Mar 2004
Posts: 1,271
|
not 100% sure, haven't used java in years. that's why i tried to give more of the loop outline than the code.
more than likely you wont type space, you probably compare it to 32 or to ' '
__________________
HT: 360 -- Sony60A3000 -- Onkyo SR605 --> Polk cs2, monitor 60s and monitor 40s w/ Bic F12 sub -- PS3 XBL:Mr X3r0 -- PSN:Mr_X3r0 Rig- Asus P6X58D Premium - intel i7 920 @3.6 - EVGA GTX570 - Corsair HX1000 - Prolimatech Mega Shadow - WD640 - COOLER MASTER ATCS 840 - OCZ Gold 6GB DDR3 1600* |
|
|
|
|
|
|
#7 | |
|
FOOL!
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
|
Quote:
![]() Just needed to know the proper method for comparing chars. I'll mess around with it and see what works.
__________________
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 |
|
|
|
|
|
|
#8 |
|
xeroyphyte
Join Date: Mar 2004
Posts: 1,271
|
looking around found function:
public static boolean isSpace(char ch); returns true for tab, NL, LF, CR and for ' '. ![]()
__________________
HT: 360 -- Sony60A3000 -- Onkyo SR605 --> Polk cs2, monitor 60s and monitor 40s w/ Bic F12 sub -- PS3 XBL:Mr X3r0 -- PSN:Mr_X3r0 Rig- Asus P6X58D Premium - intel i7 920 @3.6 - EVGA GTX570 - Corsair HX1000 - Prolimatech Mega Shadow - WD640 - COOLER MASTER ATCS 840 - OCZ Gold 6GB DDR3 1600* |
|
|
|
|
|
#9 |
|
FOOL!
Join Date: Dec 2005
Location: Miami, Florida
Posts: 3,754
|
Assignment COMPLETE! Thanks for the help guys!
![]()
__________________
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 |
|
|
|
|
|
#10 |
|
Official pain in the ass
|
Hmm... shame I saw this a bit late. I can hold my ground pretty well on Java.
What I would've done was to separare the entire string (phrase) into the individual words (an array), and then use the method you mentioned to reverse the strings. Voila.
__________________
My avatar: "An obscure and non sensical pattern made to get people to post what they think it is" - Vamp Dell XPS M1530 Core2Duo T5550 1.86Ghz | 3GB DDR2 | 8600M GT 256MB | 250GB Hdd | BenQ FP202W 20" LCD | MX1000 mouse | Inspire T5400 5.1 |
|
|
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Google (partially) loses suit to Oracle over use of Java API's | ViN86 | Mobile Devices And Smartphones | 3 | 05-17-12 10:25 AM |