Possible Duplicate:
Difference between int and int received by ParseInt in java
System.out.println("abc"+3+2); // Output: abc32
System.out.println(3+2+"abc"); //Output: 5abc
What is the reason ?
"abc"+3
converts 3 to a String
"abc3"
Then
"abc3" + 2
Converts 2 to a String as well
"abc32"
To get a numeric result do
"abc" + (3 + 2)
Because the "+" operator you wrote means "string concatenate", not "add", because it is found with left context being a string value. In this case, you get a free coercion of the right value via an implicit ToString.
You'd probably get what you wanted by writing
System.out.println("abc"+(3+2))
The "3" is found with no left context, so it is just an integer; the following "+" is found with left context integer, so it is interpreted as a real add operator, thus (3+2) gives 5. That result is found with left context of "+", so it is coerced to a string and concatenated to produce "abc5".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With