Assume that the following variables have been declared: String str2 = “Arcturan
ID: 3662870 • Letter: A
Question
Assume that the following variables have been declared:
String str2 = “Arcturan Megadonkey”;
String str3 = “Sirius Cybernetics Corporation”;
Evaluate the following expressions:
#2. str3.indexOf(“C”)
For this one, does it stop at the first C ?
#4. str3.substring(9, str3.indexof(“e”))
Same as #2, since there are multiple "e" in str3, do we stop at the first "e" encountered ?
#5. str2.toLowerCase().substring(9, 13)
Does this mean that we would evaluate the substring (9, 13) of the lower case version of str 2 ?
#6. str3.substring(18, str3.length() – 7)
For evaluating the length of an expression, do we count the total # of characters (1-30 for str3) or do we use the index (0-29 for str3) ?
Explanation / Answer
2.indexOf() method returns the index of first occurrence of specified character.
3. It stops at first occurrence of specified character.
The returned string is "ybe"
5.str2 is converted to lowercase and it extracts substring of str2.
Returns " mega"
6.the length of string iscounted as 1-30.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.