String Practice

Suppose that s is the String "slaphappy" and that t is the String "ap". What are the values of the following expressions?

  1. s.indexOf("smack")
    1. -1
    2. 0
    3. 10
    4. unknown
    5. error

  2. s.indexOf(t)
    1. -1
    2. 0
    3. 1
    4. 2
    5. 3
    6. unknown
    7. error

  3. s.indexOf(s.substring(1,4))
    1. -1
    2. 0
    3. 1
    4. 2
    5. 3
    6. unknown
    7. error

  4. s.substring(0,t.length()) + s.substring(0,s.length())
    1. 0
    2. "apslaphappy"
    3. "slaphappy"
    4. "slslaphappy"
    5. "slslap happy"
    6. unknown
    7. error

Jeffrey R.N. Forbes
Last modified: Wed Sep 28 13:12:54 EDT 2005