Ask Question

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?

+5
Answers (1)
  1. 6 May, 19:29
    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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers