Skip to main content\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 4.16 Assessment: String methods
Subgoals for using objects (creating instances).
Declare variable of appropriate class datatype.
Assign to variable: keyword new, followed by class name, followed by ().
-
Determine whether parameter(s) are appropriate (API)
Number of parameters
Data types of the parameters
Exercises Exercises
1.
Q1: What is the output of the following code?
String temp = "abcde";
System.out.println(temp.length());
0
4
5
6
an error occurs
2.
Q2: What is the output of the following code?
String temp = "abcdefghijklmnopqrstuvwxyz";
System.out.println(temp.indexOf("fgk"));
0
5
6
-1
an error occurs
3.
Q3: What is the output of the following code?
String temp = "catcatcat";
System.out.println(temp.indexOf("cat"));
0
3
4
6
7
4.
Q4: What is the output of the following code?
String temp = "abcdefghijklmnopqrstuvwxyz";
System.out.println(charAt.indexOf(3));
c
d
e
f
5.
Q5: What is the output of the following code?
String temp = "onetwothreefour";
System.out.println(temp.substring(3,7));
one
two
three
four
an error occurs
6.
Q6: What is the output of the following code?
String temp = "onetwothreefour";
System.out.println(temp.substring(6));
three
four
threefour
twothreefour
an error occurs
You have attempted
of
activities on this page.