Okay, so i have a dilemma. I have a int variable called rank that
stores integers (obviously). however, i need to display these values as
chars in another method. casting dosent help because it just converts
the integer into the unicode character which isn't the same as the
number.
heres a snippet of the problem:
char r; // as you can see, its gets pretty
repetitive and boring
if (rank == 2)
r = '2';
if (rank == 3)
r = '3';
if (rank == 4)
r = '4';
....
return r;
is there a trick to make my int number the equivalent char number?
Patricia Shanahan - 25 Sep 2006 23:32 GMT
> Okay, so i have a dilemma. I have a int variable called rank that
> stores integers (obviously). however, i need to display these values as
[quoted text clipped - 17 lines]
>
> is there a trick to make my int number the equivalent char number?
Does Character.forDigit() do what you want?
Patricia
IchBin - 26 Sep 2006 00:37 GMT
> Okay, so i have a dilemma. I have a int variable called rank that
> stores integers (obviously). however, i need to display these values as
[quoted text clipped - 17 lines]
>
> is there a trick to make my int number the equivalent char number?
Roedy has an online applet, on his website, that will let you select the
from and to Object types and offer the available Java statement to do
the conversion.
http://mindprod.com/applets/converter.html
You can also download it also.

Signature
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Jeff - 26 Sep 2006 02:55 GMT
> Okay, so i have a dilemma. I have a int variable called rank that
> stores integers (obviously). however, i need to display these values as
[quoted text clipped - 17 lines]
>
> is there a trick to make my int number the equivalent char number?
I'm going to guess that you really mean that you want to convert it to
a character string, to display in a textbox or the like.
The trick is to use String.format
To convert your integer to a string, use
String r = String.format("%d", rank);
hth
/js
Tor Iver Wilhelmsen - 27 Sep 2006 17:44 GMT
> is there a trick to make my int number the equivalent char number?
char r = '0' + rank;
Joan C - 30 Sep 2006 15:25 GMT
> Okay, so i have a dilemma. I have a int variable called rank that
> stores integers (obviously). however, i need to display these values as
[quoted text clipped - 17 lines]
>
> is there a trick to make my int number the equivalent char number?
The following single line should do what you want:
char r = (char) (rank+48);
as the ascii characters 0-9 equte to 48, 49, 50 ... 57.