Task 6 of 15 · 0 solved · 15 to go0%
You can read the problem, but answers are checked only for signed-in students. Sign in to answer →

1.5 Strings — building a message

Lesson

Building a message with values

To combine text with a computed number, put the math in parentheses so it is added first, then joined to the text.


Worked example

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?


What does "Sum: " + (2 + 3) print?


Given int a = 3, b = 4;, fill the blank so it prints Total: 7.


Assemble an expression that produces Hi, Ada! when name holds "Ada".


Type exactly what this program prints.

public class Main { public static void main(String[] a){
    String name = "Ada";
    System.out.println("Hi, " + name);
}}