Week 15 · 15.5 · Fri, Nov 13 · Do Now
Do Now
Work every question in your notebook. Do it on your Chromebook with your ID.
Predict
What is printed?
System.out.println("Bus " + 4 + 2);- Bus 42
- Bus 6
- 42
- Bus 4 + 2
Predict
What is printed? The first line printed is first.
System.out.println(5 + 2 + " laps"); System.out.println("laps: " + 5 + 2);- 7 laps, then laps: 52
- 52 laps, then laps: 52
- 7 laps, then laps: 7
- 52 laps, then laps: 7
Error analysis
first holds Mia and last holds Cruz. A student wanted Mia Cruz, but System.out.println(first + last); prints MiaCruz. What is the mistake?
- + never adds a space, so the line needs " " joined between first and last.
- last needs quotation marks around it.
- + should be - between the two strings.
- println should be print.
Length
What is printed?
String s = "Hi"; s = s + " there"; System.out.println(s.length());
- 8
- 7
- 2
- Hi there
Output
Write exactly what is printed, one line for each println.
String pet = "Rex"; int age = 6; System.out.println(pet + " is " + age); System.out.println(age + 2 + " in two years"); System.out.println("In two years: " + age + 2);