ICSE Class 10 Computer Applications Question 26 of 30

Solved 2024 Specimen Paper ICSE Class 10 Computer Applications — Question 26

Back to all questions
26
Question

Question 2(vi)

Write the output of the following String methods:

(a) "ARTIFICIAL".indexOf('I')

(b) "DOG and PUPPY".trim().length()

Answer

(a)

Output
3
Explanation

indexOf() returns the index of the first occurrence of the specified character within the string or -1 if the character is not present. First occurrence of 'I' in "ARTIFICIAL" is at index 3 (a string begins at index 0).

(b)

Output
13
Explanation

trim() removes all leading and trailing space from the string and length() returns the length of the string i.e., the number of characters present in the string. Thus, the output is 13.