Lesson 6 - Activity 1 - Can you manipulate strings?

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,

  1. Declare a string “Hello”
  2. Declare a second string “World”
  3. Add together and print the result
  4. 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