Ask Question
20 June, 08:35

String sentence;

String str1, str2, str3, str4;

int length1;

sentence = " First exam is on Monday. ";

str1 = sentence. substring (6, 12);

str2 = str1. substring (0, 4);

str3 = sentence. replace (' i ', ' # ');

str4 = sentence. indexOf ("on");

length1 = sentence. length ();

1. Based on the code above, what is the value of str2?

+4
Answers (1)
  1. 20 June, 10:58
    0
    "exa"

    Explanation:

    str1 will create a substring of sentence from index 6 - 12

    str1 = " exam "

    Index 6 is the spacing between 'first' and 'exam' while index 12 is the letter 'i' of 'is'

    str2 will create a substring of str1 from index 0 - 4

    str2 = " exa"

    Index 0 is the spacing before the 'exam' and index 4 is the letter 'm' of the ' exam'

    The last position in the index is not considered when creating a substring. The substring stop a letter before the last index given as argument
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “String sentence; String str1, str2, str3, str4; int length1; sentence = " First exam is on Monday. "; str1 = sentence. substring (6, 12); ...” in 📙 Engineering if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers