0
What's the logic behind these two outputs?
System.out.println(1+1+(1+"1")); // output 211 System.out.println(1+1+(1+"1").length()); // output 4 Why isn't length() returning 3 instead? I know it does if you place another set of parentheses before the first "1" and before the dot operator.
2 Respostas
+ 5
(1 + "1") evaluates to "11".
"11" is a string containing 2 characters and thus "11".length() evaluates to 2.
1 + 1 + 2 evaluates to 4.
0
Seb TheS Thank you 🤦🏿♂️