+ 33

JAVA : System.out.println(1+2+” = “+1+2); //output 3=12 Please can anyone explains why ?

I'm confuse about this fact .All answers are appreciated...

27th Apr 2018, 10:40 AM
Hans Larry Mba Bekale
Hans Larry Mba Bekale - avatar
12 odpowiedzi
+ 20
Ariela thank a lot for your answers...now I get it. finally it's really clear on my mind.😊
27th Apr 2018, 11:02 AM
Hans Larry Mba Bekale
Hans Larry Mba Bekale - avatar
+ 18
The first 1+2 is treated as integers, so you add them like regular numbers. The second 1+2 is placed after the string “=“, meaning anything after it is considered a string too. So the second 1+2 are literally the numbers 1 and 2 glued together
27th Apr 2018, 10:54 AM
Ariela
Ariela - avatar
+ 17
got!
10th May 2018, 7:24 PM
Hans Larry Mba Bekale
Hans Larry Mba Bekale - avatar
+ 16
abderrahim bouali !😊
4th May 2018, 12:14 PM
Hans Larry Mba Bekale
Hans Larry Mba Bekale - avatar
+ 16
😂😂😂Mark Kendrick...please you, send me one of your contacts or link ,i'll contact you.
10th May 2018, 7:19 PM
Hans Larry Mba Bekale
Hans Larry Mba Bekale - avatar
+ 8
To fix this, do any mathematical calculations in System.out.println inside parenthesis. For instance, System.out.println((1+2)+”=“+(1+2));
27th Apr 2018, 10:55 AM
Ariela
Ariela - avatar
+ 2
System. out. printf("%d = %s" , 1+2 ,String.valueOf(1+2))
1st Jun 2018, 9:00 AM
Armin Shoughi
Armin Shoughi - avatar
+ 1
My phone can't stop vibrating can how can I contact you privately 😂😂😂😂
10th May 2018, 7:12 PM
Mark Kendrick
Mark Kendrick - avatar
+ 1
Markodhis96@gmail.com
10th May 2018, 7:23 PM
Mark Kendrick
Mark Kendrick - avatar
+ 1
Once added an integer to a string the answer will be a string. So 1+2+” = “+1+2 =3+” = “+1+2 =“3 = “+1+2 =“3 = 1”+2 =“3 = 12”
3rd Jun 2018, 5:58 AM
Void Skeleton
0
If you adds an object to a string, that equals you adds that object.toString() to a string.
1st May 2018, 12:09 PM
Void Skeleton
- 2
the first 1+2 is concatenated as integer the second 1+ 2 come after a string , they will be automatically converts to a string and they will be concatenated as a two strings(no math here hhhhh)
4th May 2018, 12:11 PM
abderrahim bouali
abderrahim bouali - avatar