Computer Science Canada number reversal |
Author: | Prince [ Thu Apr 03, 2003 9:48 pm ] |
Post subject: | number reversal |
is there a way i can reverse a number and store it in a variable instead of just doing it digit by digit and outputting it to the screen? |
Author: | Tony [ Thu Apr 03, 2003 9:56 pm ] |
Post subject: | |
what you mean reverse your number? like 123 to 321? if so, you gotta treat it as a string and reverse it that way. intstr and strint |
Author: | Prince [ Thu Apr 03, 2003 10:00 pm ] |
Post subject: | |
how would i do that? |
Author: | Tony [ Thu Apr 03, 2003 10:07 pm ] | ||
Post subject: | |||
to reverse / flip a word
to convert integer to string - intstr() to convert string back to integer - strint() |
Author: | Prince [ Thu Apr 03, 2003 10:15 pm ] |
Post subject: | |
riiigh... i dont get it ![]() ![]() |
Author: | yuethomas [ Thu Apr 03, 2003 10:47 pm ] | ||
Post subject: | |||
Let's talk about string reversal first. The idea is to put the last character of the original string as the first character of the resultant string, the second last character of the original string as the second character of the resultant string, and so on. So, supposing you need to flip a String (ugh, capitalised "String", Java habit ![]()
Everything else should be self-explanatory. Convert your integer to a String, reverse it using the above algorithm, and convert the resultant String back into an integer... Ta-da. Thx for explaining it better ![]() |
Author: | Prince [ Tue Apr 08, 2003 10:27 am ] | ||
Post subject: | |||
k now im having trouble converting from int to string and back...
sumbody tell me y this isnt working... im about to giv up all hope on this stupid function (even tho it needs to be there ![]() |
Author: | Asok [ Tue Apr 08, 2003 10:33 am ] |
Post subject: | |
incorrect usage of intstr think about it like this intstr(n) = string. you're trying to assign that to an integer, which doesn't make any sence. |
Author: | MysticAngel [ Tue Apr 08, 2003 5:29 pm ] | ||
Post subject: | |||
this is how i did it.
|
Author: | Prince [ Tue Apr 08, 2003 6:03 pm ] |
Post subject: | |
yea i kno it would work like that but then how would i store it into a variable? thats wat im havin trouble with |
Author: | Blade [ Tue Apr 08, 2003 7:34 pm ] | ||
Post subject: | |||
intstr converts integers to strings strint converts strings to integers.. |
Author: | Prince [ Tue Apr 08, 2003 9:35 pm ] | ||
Post subject: | |||
ok dats all well and good wit words but say it started of like this:
would that work? |
Author: | Prince [ Tue Apr 08, 2003 9:41 pm ] | ||
Post subject: | |||
would this work? im gonna kill this function if it doesnt start to work soon ![]() |
Author: | Catalyst [ Tue Apr 08, 2003 9:46 pm ] | ||
Post subject: | |||
|
Author: | Prince [ Tue Apr 08, 2003 10:21 pm ] |
Post subject: | |
YES!!!!! thank u Catalyst... i knew u'd feel sorry for me sooner or later ![]() |