Advertisements
Advertisements
प्रश्न
What will be the value stored in the variable 'c' if the following statement is executed?
c = "COMPUTER".charAt("COMPUTER".indexOf('P'))
विकल्प
3
4
P
M
MCQ
उत्तर
P
Explanation:
charAt(int index) returns a character from the given index of the string, and indexOf(char ch) returns the index of the first occurrence of a character in the string.
Since P is at 3rd position so indexOf('P') will return 3 and charAt(3) function will return the character at the third index i.e., 'P'. So, the given statement is solved as follows:
c = "COMPUTER".charAt("COMPUTER ".indexOf('P'))
c = "COMPUTER".charAt(3)
c = 'P'
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?