Chapter 4: Fundamental Data Types
Strings
- A string is a sequence of characters.
- String concatenation operator: +
- String methods: length(), substring(), ...
- Converting a string to an integer, int year = Integer.parseInt("2008");
- Converting a string to a double, double price = Double.parseDouble("2.25");
Reading Input
- Use the java.util.Scanner class
- Scanner in = new Scanner(System.in);
- int year = in.nextInt();
- double price = in.nextDouble();
- String word = in.next();
- String words = in.nextLine();
Lecture Code