Computer Applications
State the output of the following program segment:
String s = "Examination";
int n = s.length();
System.out.println(s.startsWith(s.substring(5, n)));
System.out.println(s.charAt(2) == s.charAt(6));
Java
Java String Handling
ICSE 2012
35 Likes
Answer
false
true
Working
Putting the value of n in s.substring(5, n), it becomes s.substring(5, 11). This gives "nation". As s does not start with "nation" so s.startsWith(s.substring(5, n)) returns false.
s.charAt(2) is a and s.charAt(6) is also a so both are equal
Answered By
15 Likes