+ 15

String concatenation in Java

Why is the output 3solo12? How does it work actually? System.out.println(1+2+"solo"+1+2);

13th Mar 2017, 8:08 PM
Shamima Yasmin
Shamima Yasmin - avatar
4 Respostas
+ 5
because you are making an output (reading ltr due to operator priorities) start as an int, convert to string, and attempting to convert back which a string even as a priminitve cannot turn into an int. to accomplish 3solo3 you would have to put parentheses around the last 1+2 to have that calculated first, same as if you used multiplication in the middle
13th Mar 2017, 8:13 PM
William La Flamme
William La Flamme - avatar
+ 12
Now I got it, thanks for the explanation :)
13th Mar 2017, 8:29 PM
Shamima Yasmin
Shamima Yasmin - avatar
0
concatenation means combining of the given message (or) string. ex: System.out.println("a+bc+c"); output: abcc
20th Mar 2017, 4:03 PM
B.sruthireddy
B.sruthireddy - avatar
0
thanks for everything b.sruthireddy
28th Mar 2017, 1:35 AM
vamsi
vamsi - avatar