Input & Expressions – Part 2
Use nextLine safely, trim whitespace, parse numbers from text, and control concatenation vs addition with parentheses.
Lesson Goals
Goals: Use nextLine() safely, trim input, parse numbers from text, and understand when + concatenates vs adds.
Newline Trap
Newline trap: After nextInt() or nextDouble(), a leftover newline may cause the next nextLine() to return empty.
Fix: call an extra nextLine() to consume it, or read lines and parse numbers.
All lessons in this course
- Variables & Data Types
- Input & Expressions – Part 1
- Input & Expressions – Part 2