Addition of two numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Addition of two numbers

class Test { public static void main(String args[]) { String a="6",b="3",c; c=a+b; System.out.print(c); } } when i am using String. it is not showing any error, but when i changed it to char, it is showing error. why???

5th Dec 2016, 10:23 AM
Somnath Ghosh
Somnath Ghosh - avatar
1 Answer
+ 2
Because char stands for a char. Only 1. if you sums 2 char, it does not enter in other char, because the result is 2 char. char a = "X"; char b ="Y"; print(a+b);// this shows: XY. You can sum 2 chars (char a="x", b="y") and add it to String c = a + b;
5th Dec 2016, 10:36 AM
Nahuel
Nahuel - avatar