0
Pls explain.... I have exam tomorrow....đ
In java, the output of : System.out. println ("Result = " + 4+2); is : Result = 42....but the output of System.out.println('c' + 4+2) is 105 (taking the ASCII value)... I don't understand the working of '+' as a concatenation operator in both cases....
4 Respostas
+ 2
" " (double quotes) is a string.
' ' (single quotes) is a character (ascii value).
If we add something to a string, it gets concatenated.
If we add something to a char, it adds the number to an ascii value.
+ 2
string + int is string concatenation. The int will be converted to string.
char + int is ASCII value addition. The result is an int.
+ 1
Aswin V Sivan
After string value if you try add number then it will just concatenate with string. To avoid this you can use parenthesis like:
System.out.println("Result = " + (4 + 2));
+ 1
Thank U everyone... I am saved