Ask Questions?

View Latest Questions

Advertisement


 
 

Java: String Exercise 2
Posted on: February 5, 2008 at 12:00 AM
String Exercise 2

Java: String Exercise 2

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.

1__________h.length()
2__________h.substring(1)
3__________h.toUpperCase()
4__________h.toUpperCase().toLowerCase()
5__________h.indexOf("H")
6__________h.startsWith("ell")
7__________"Tomorrow".indexOf("o")
8__________"Tomorrow".indexOf("o", 3)
9__________"Tomorrow".lastIndexOf('o')
10__________"Tomorrow".substring(2,4)
11__________a.length() + a
12__________"a = \"" + a + "\""
13__________(a.length() + a).startsWith("a")
14__________a.length() + a.startsWith("a")
15__________">>>" + a.length() + a.startsWith("a")
16__________a.substring(1,3).equals("bc")
17__________a.substring(1,3) == "bc"
18__________"a".compareTo("c")
19__________"a".compareTo("A")
20__________s.trim().charAt(2)

String Exercise 2 - Answers

Advertisement


DMCA.com