CH9 – Substrings

  1. Open DrJava and expand the Interactions pane.
  2. Enter the following code.
Welcome to DrJava.  Working directory is /Users/jamesbrannan
> String fruit = "banana";
> fruit.substring(0)
"banana"
> fruit.substring(2)
"nana"
> fruit.substring(6)
""
  1. Now enter the following code.
> fruit.substring(0,3)
"ban"
> fruit.substring(2,5)
"nan"
> fruit.substring(6,6)
""