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
Post a Comment