Back to questions
JuniorTheoryCommon
What does the program print?
public class Main {
public static void main(String[] args) {
System.out.println(1 + 2 + "3" + 4 + 5);
}
}3345
- Expecting
339: once the left side is a string, each+glues, so4and5are appended one by one, not added. - Expecting
12345:+runs left to right, and1 + 2sees two numbers, so it adds them into3before any string appears.
- How would you change the expression so that it prints
339? - What does
"" + 1 + 2print, and why?