To combine text with a computed number, put the math in parentheses so it is added first, then joined to the text.
System.out.println("Sum: " + 2 + 3); // Sum: 23 (left to right) System.out.println("Sum: " + (2 + 3)); // Sum: 5 (parentheses first)
▶ Try it: run this, then change something and run it again.
What does "Sum: " + 2 + 3 print?
"Sum: " + 2 + 3
What does "Sum: " + (2 + 3) print?
"Sum: " + (2 + 3)
Given int a = 3, b = 4;, fill the blank so it prints Total: 7.
int a = 3, b = 4;
Total: 7
Assemble an expression that produces Hi, Ada! when name holds "Ada".
Hi, Ada!
name
"Ada"
Type exactly what this program prints.
public class Main { public static void main(String[] a){ String name = "Ada"; System.out.println("Hi, " + name); }}