Ask Question
6 September, 10:33

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?

+3
Answers (1)
  1. 6 September, 10:40
    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?
Find 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 you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers