Java: String Exercises 1

Name __________________________________________

(10 points) Given the following local variable declarations:

      String a = "abc";
      String s = a;
      String t;

What is the value of the following expressions (or ERROR)?

  1. __________ s.length()
  2. __________ t.length()
  3. __________ 1 + a
  4. __________ a.toUpperCase()
  5. __________ "Tomorrow".indexOf("r")
  6. __________ "Tomorrow".lastIndexOf('o')
  7. __________ "Tomorrow".substring(2,4)
  8. __________ (a.length() + a).startsWith("a")
  9. __________ s == a
  10. __________ a.substring(1,3).equals("bc")

String Exercises 1 - Answers