0
How i print xy with using char data type
char a = 'x'; char b = 'y'; char c = a+b;
8 Antworten
+ 9
char data type can only store a single character at a time. Therefore if you want to concatenate/combine multiple characters together, you'll need a string.
The simplest way would be something like this:-
String c = new String(new char[] { a, b });
and I hope you do notice that string is actually an array of characters. 😉
+ 1
char[] c = {a, b};
Or
String c = a + b; It's the same
+ 1
is it not possible to add with using char ?
+ 1
More than one char became a String, so not
+ 1
ok thanx , I was thinking may be it is possible to add only single character with char
+ 1
You can cast the chars to int (get the ASCII code) and then sum them and convert the result back to char. But i think the result of this operation isn't what you want
+ 1
thank you
+ 1
Here it is the result of the sum with integer cast if you are Interested
https://code.sololearn.com/cPvjP4dZZhc4/?ref=app