Computer Applications
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");
Java
Java String Handling
ICSE 2017
27 Likes
Answer
Output of the above code is:
0
Today i Holiday
Working
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.
Answered By
14 Likes