Home Java Java-tips Data Strings Q-fi-string-exercises String Exercise 2 - Answers

Ask Questions?

View Latest Questions

Advertisement


 
 

String Exercise 2 - Answers
Posted on: July 26, 2006 at 12:00 AM
Assume the following:> String s, t, h, a; String n, e

Java: String Exercise 2 - Answers

Name ______________________

Assume the following:> String s, t, h, a; String n, e; int i; h = "Hello"; s = " How are you? "; a = "abc"; n = null; e = "";

Give the values of the following expressions, or illegal.

15h.length()
2elloh.substring(1)
3HELLOh.toUpperCase()
4helloh.toUpperCase().toLowerCase()
50h.indexOf("H")
6falseh.startsWith("ell")
71"Tomorrow".indexOf("o")
83"Tomorrow".indexOf("o", 3)
96"Tomorrow".lastIndexOf('o')
10mo"Tomorrow".substring(2,4)
113abca.length() + a
12a = "abc""a = \"" + a + "\""
13false(a.length() + a).startsWith("a")
14illegala.length() + a.startsWith("a")
15">>>3true"">>>" + a.length() + a.startsWith("a")
16truea.substring(1,3).equals("bc")
17falsea.substring(1,3) == "bc"
18< 0"a".compareTo("c")
19> 0"a".compareTo("A")
20ws.trim().charAt(2)
Copyleft 2003 Fred Swartz MIT License
Advertisement


DMCA.com