Self-Review Questions

  1. Given the following local variable declarations:
    String a = "abc";
    String s = a;
    String t;
    
    What is the value of the following statements?
     
    1. __________ 'b' + 2 == 'd'
       
    2. __________ (char)('5' - 0)
       
    3. __________ t.length()
       
    4. __________ s == a
       
    5. __________ 5 + a
       
    6. __________ a.toUpperCase()
       
    7. __________ (a.length() + a).startsWith("a")
       
    8. __________ "Algorithm".indexOf("r")
       
    9. __________ "Algorithm".substring(0,4)
       
    10. __________ "Algorithm".substring(2).startWith("go")
       
    11. __________ a.substring(1) == "bc"
       
    12. __________ "ab".compareTo("ac")
       

     

  2. Write a method that counts vowels in a string.

     

  3. Caesar's cipher. In this cipher each letter in the text is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 3, A would be replaced by D, B would become E, and so on. Implement Caesar's cipher.