(a) Give the output of the following string functions :
(i) “MISSISSIPPI”.indexOf(‘S’) + “MISSISSIPPI”.lastIndexOf(‘I’)
(ii) “CABLE”.compareTo(“CADET”)
Answers
Answered by
25
Ans.
(i) “MISSISSIPPI”.indexOf(‘S’) + “MISSISSIPPI”.lastIndexOf(‘I’)
= 2 + 10
= 12
(ii) String’s compareTo method compares ASCII values of characters starting from the left.
“CABLE”.compareTo(“CADET”)
The first and seconds characters are the same in both the strings. So, we compare the third characters.
Compare B and D = ASCII value of B – ASCII value of D
= 66 – 68
= -2
Answered by
12
(i)Output:2+10=12
(ii)Output:-2
(ii)Output:-2
Similar questions
Social Sciences,
6 months ago
Math,
6 months ago
English,
6 months ago
India Languages,
1 year ago
Math,
1 year ago
Math,
1 year ago