Why do the integers get concatenated here instead of getting added? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why do the integers get concatenated here instead of getting added?

https://code.sololearn.com/cqvYuINFy4Z2/?ref=app Here I used " " before for spacing, but why 6+7 gets printed as 67 instead of 13. Why 6+7 is getting taken as string instead of an integer?

3rd Aug 2021, 4:16 PM
Srinath
4 Answers
+ 5
If you want to output a result from expression evaluation, you could wrap it up in parentheses. System.out.println( " " + ( 6 + 7 ) );
3rd Aug 2021, 4:22 PM
Ipang
+ 3
Verstappen JVM understand may u want to add numbers as string . If you put brackets to (6+7) then it treat as may be programmer want to add numbers.
3rd Aug 2021, 4:26 PM
❤☆Nani☆❤
❤☆Nani☆❤ - avatar
+ 3
♡Nani♡ Ipang Martin Taylor thanks I got it now 👍
3rd Aug 2021, 4:32 PM
Srinath
+ 3
Because the compiler after the quotes interprets the + symbol as a string concatenation character and automatically converts to a string everything that comes after the concatenation character, the result is "" + "6" + "7"
3rd Aug 2021, 4:41 PM
Solo
Solo - avatar