Home / Questions / Write the output for the following: String s="Today is Test"; System.out.println(s.indexOf('T')); System.out.println(s.substring(0,7) + " " +"Holiday");
Explanatory Question

Write the output for the following:

String s="Today is Test";
System.out.println(s.indexOf('T'));
System.out.println(s.substring(0,7) + " " +"Holiday");

👁 71 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

Output of the above code is:


0
Today i Holiday

As the first T is present at index 0 in string s so s.indexOf('T') returns 0. s.substring(0,7) extracts the characters from index 0 to index 6 of string s. So its result is Today i. After that println statement prints Today i followed by a space and Holiday.