Casting int to char in Java -


i'm looking straightforward answer , can't seem find one.

i'm trying see if following valid. want take integer 7 , turn character '7'. allowed:

int digit = 7; char code = (char) digit;  

thank in advance help!

this conversion allowed, result won't expect, because char 7 bell character whereas '7' 55 (0x37). because numeric characters in order, starting '0' @ 48 (0x30), add '0', cast result char.

char code = (char) (digit + '0'); 

you may take @ unicode characters, of printable ascii characters same codes.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -