Computer Science, asked by Siddhartha36, 1 year ago

distinguish between x.indexof ( 'r') and x. indexof ( 'r', n)

Answers

Answered by siddhartharao77
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.

Siddhartha36: thanks bro
Answered by dolas1112
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