+ 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...
12 Respuestas
+ 20
Ariela thank a lot for your answers...now I get it. finally it's really clear on my mind.😊
+ 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
+ 17
got!
+ 16
abderrahim bouali !😊
+ 16
😂😂😂Mark Kendrick...please you, send me one of your contacts or link ,i'll contact you.
+ 8
To fix this, do any mathematical calculations in System.out.println inside parenthesis. For instance, System.out.println((1+2)+”=“+(1+2));
+ 2
System. out. printf("%d = %s" , 1+2 ,String.valueOf(1+2))
+ 1
My phone can't stop vibrating can how can I contact you privately 😂😂😂😂
+ 1
Markodhis96@gmail.com
+ 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”
0
If you adds an object to a string, that equals you adds that object.toString() to a string.
- 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)