Computer Science, asked by T4Talent, 1 year ago

(a) Give the output of the following string functions :
(i) “MISSISSIPPI”.indexOf(‘S’) + “MISSISSIPPI”.lastIndexOf(‘I’)
(ii) “CABLE”.compareTo(“CADET”)

Answers

Answered by tiara5
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 oswin
12
(i)Output:2+10=12

(ii)Output:-2
Similar questions