Computer Science Canada Converting Int to Char |
Author: | Prince Pwn [ Mon May 28, 2007 10:33 am ] | ||||
Post subject: | Converting Int to Char | ||||
I need to convert an Integer into a Character so I could use a for loop to assign a number to a variable when I press a 1 2 3 or 4. For some reason it isn't reading the for loop input. I'm basically needing a way to automate:
Here is my code:
|
Author: | HeavenAgain [ Mon May 28, 2007 9:19 pm ] | ||||||
Post subject: | Re: Converting Int to Char | ||||||
hello, the problem should be if (key == char (i)) what do you mean by char (i) ? trying to cast an int to a char ? then it should be
since i is in the for loop, i dont get the part where you enter a number? but anyways converting a String using java the code is
example
that would give you 100 as integer by the way,i suggest you use another variable for this ![]() ![]() |
Author: | OneOffDriveByPoster [ Tue May 29, 2007 8:03 am ] | ||
Post subject: | Re: Converting Int to Char | ||
Prince Pwn @ Mon May 28, 2007 10:33 am wrote:
Consider this: (char)0x30 is '0'. So your conversion should be (char)(i | 0x30)--this is okay because you control the value of "i"; this will not work with # > 9. You can also check out Java characters and their relation to Unicode. |
Author: | Prince Pwn [ Wed May 30, 2007 6:01 pm ] |
Post subject: | Re: Converting Int to Char |
Thankyou. |