Strings, Inputs and Outputs Topic 4.3.6 / Core
Key points
  • how to manipulate strings of text;
  • how to input and output data in Java.
  • String;
  • concatenation;
  • append.
Related topics


What is a String?

  1. Presentation on Strings, Inputs and OUtput
  2. Here's a program that uses Strings. Save Target As, then open in BlueJ, compile and run. Look at the code, especially at the way the String variable firstname and the String literals are concatenated (strung together) in the output lines.
    Note that this project has some extra code at the bottom - don't touch it as it lets you do the inputting and simplifies the outputting.
  3. Expand the program to input the user's age (as an int) and their phone number (as a String).
  4. Try some of the ways of manipulating Strings described in the presentation as you experiment with HelloThere.
  5. Extension work. Given the String methods listed in this document, what would be the results of these calls?
    a. name.charAt(4) if name is "Albert"
    b. name.concat(" the Frog")
    c. name.endsWith ("ret") if name is back to "Albert"
    d. name.equalsIgnoreCase ("alberT")
    e. name.indexOf ('r')
    f. name.length ()
    g. name.toLowerCase ()
  6. Work through the problems in the Java Problem Set 1<.
  7. Try some of the programming exercises at the end of Eck's chapter 2.