distinguish between x.indexof ( 'r') and x. indexof ( 'r', n)
Answers
Answered by
2
When you compile that code u will get an error saying that x and n are not defined.
Code : It should be 'x'.indexOf('r') and 'x'.indexOf('r','n').
Output: -1 and -1.
Reason: The index of the first occurrence of the specified value: -1 if not found.
Code : It should be 'x'.indexOf('r') and 'x'.indexOf('r','n').
Output: -1 and -1.
Reason: The index of the first occurrence of the specified value: -1 if not found.
Siddhartha36:
thanks bro
Answered by
3
x.indexOf('r') returns the index of the first occurrence of 'r'.
x.indexOf('r',n) returns the index of the next occurrence of 'r' from the nth position of the string
Similar questions