180k views
5 votes
Given the following code, what indexes must be passed to the substring method to produce the new String with the value "SCORE"? What indexes to substring produce "fouryears"?

// index 012345678901234567890123456789
String quote = "Four score and seven years ago";
String expr1 = quote.substring(a, b).toUpperCase(); // "SCORE"
String expr2 = quote.toLowerCase().substring(c, d) + quote.substring(e, f); // "fouryears"
a.
b.
c.
d.
e.
f.

1 Answer

3 votes

Answer:

For expr1 = index 5, length 5

For expr2 = index 0, length 4 and index 21, length 5

string quote = "Four score and seven years ago";

string expr1 = quote.Substring(5, 5).ToUpper(); // "SCORE"

string expr2 = quote.Substring(0, 4) + quote.Substring(21, 5).ToLower(); // "fouryears"

Console.WriteLine(expr1);

Console.WriteLine(expr2);

Step-by-step explanation:

Then code is written in c# and it produces SCORE and f

ouryears

Substring takes 2 arguments, the start of the specific character and the length

User Xiaolong
by
5.1k points