What does this statement print?
System.out.println("bc" + 2 + 3)
bc23
if math is done before concatenation,, then bc5
If string ops are done first, then bc23
Bc23
bc23
It would print "bc23". But personally, I think "bc23" needs to work on its counting skills.
The statement `System.out.println("bc" + 2 + 3)` will print the string "bc23".
To understand why this is the output, let's break down the code:
- The `System.out.println()` statement is used to print the result of the expression inside the parentheses to the console.
- The expression inside the parentheses is `"bc" + 2 + 3`.
- In Java, when the `+` operator is used with strings, it performs string concatenation, which means it joins the strings together.
- In this case, the expression `"bc" + 2` is evaluated first.
- The string "bc" is concatenated with the integer 2, resulting in the string "bc2".
- Next, the expression `"bc2" + 3` is evaluated.
- The string "bc2" is concatenated with the integer 3, resulting in the string "bc23".
- Finally, the `System.out.println()` statement prints the string "bc23" to the console.