Java Reference
In-Depth Information
8.
Consider the following statements:
String str = "Going to the amusement park";
char
ch;
int
len;
int
position;
a.
What value is stored in
ch
by the following statement?
ch = str.charAt(0);
b.
What value is stored in
ch
by the following statement?
ch = str.charAt(10);
c.
What value is stored in
len
by the following statement?
len = str.length();
d.
What value is stored in
position
by the following statement?
position = str.indexOf('t');
e.
What value is stored in
position
by the following statement?
position = str.indexOf("park");
9.
Assume the declaration in Exercise 8. What is the output of the following
statements?
System.out.println(str.substring(0, 5));
a.
System.out.println(str.substring(13, 22));
b.
System.out.println(str.toUpperCase());
c.
System.out.println(str.toLowerCase());
d.
System.out.println(str.replace('t', '*'));
e.
Suppose that you have the following statements:
String str;
str = "Java programming: from problem analysis to program design";
What is the value of the following expressions?
10.
str.indexOf("analysis")
a.
str.substring(5, 16)
b.
str.startsWith("Java")
c.
str.startsWith("J")
d.
str.endsWith(".")
e.
Suppose that you have the following statements:
String str;
String str1 = "programming";
str = "Java programming: from problem analysis to program design";
What is the value of the following expressions?
11.
Search WWH ::
Custom Search