Computer Applications
Give output of the following String methods:
"SUCESS".indexOf('S') + "SUCCESS".lastIndexOf('S')
- 0
- 5
- 6
- -5
Java String Handling
ICSE 2022
11 Likes
Answer
6
Reason — indexOf() returns the index of the first occurrence of the specified character within the string and lastIndexOf() returns the index of the last occurrence of the specified character within the string. Since a string begins with index 0, the given methods are evaluated as follows:
"SUCESS".indexOf('S') + "SUCCESS".lastIndexOf('S')
⇒ 0 + 6
⇒ 6
Answered By
6 Likes
Related Questions
Return data type of isLetter(char) is …………… .
- Boolean
- boolean
- bool
- char
Method that converts a character to uppercase is …………… .
- toUpper()
- ToUpperCase()
- toUppercase()
- toUpperCase(char)
Corresponding wrapper class of float data type is …………… .
- FLOAT
- float
- Float
- Floating
…………… class is used to convert a primitive data type to its corresponding object.
- String
- Wrapper
- System
- Math