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)
-
-
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());
2.
Q2: What is the output of the following code?
String temp = "abcdefghijklmnopqrstuvwxyz";
System.out.println(temp.indexOf("fgk"));
3.
Q3: What is the output of the following code?
String temp = "catcatcat";
System.out.println(temp.indexOf("cat"));
4.
Q4: What is the output of the following code?
String temp = "abcdefghijklmnopqrstuvwxyz";
System.out.println(charAt.indexOf(3));
5.
Q5: What is the output of the following code?
String temp = "onetwothreefour";
System.out.println(temp.substring(3,6));
6.
Q6: What is the output of the following code?
String temp = "onetwothreefour";
System.out.println(temp.substring(6));
You have attempted
of
activities on this page.