Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote