Time: 15 minutes
Purpose: This activity helps you get familiar with working with strings
Introduction: You’re now familiar with what happens when you use an operator between numbers, what happens when you’re using a String?
Task: Perform the following actions,
- Declare a string “Hello”
- Declare a second string “World”
- Add together and print the result
- Declare an int of 4 and add it to the string. Print it. What happens?
String newLine = System.getProperty("line.separator"); //This will retrieve line separator dependent on OS.
String printMe = "Hoi, ik heet Huib!";
System.out.println(newLine + printMe);
String String1 = "Hello ", String2 = "world ", combinedString;
int intToAddToString = 666;
combinedString = String1 + String2;
System.out.println(combinedString);
combinedString += intToAddToString;
System.out.println(combinedString);
Great work there, you’ve shown a good understanding of operations with strings