ICSE Class 10 Computer Applications
Question 8 of 30
Solved Sample Paper 2 — Question 8
Back to all questions 8
Question Question 1(viii)
What will be the output of the following code?
String a[] = {"MI", "Samsung", "Micromax", "One Plus"};
System.out.println(a[3].length());- 8
- 7
- 5
- 9
8
Reason — a[3] refers to the fourth element of the array, which is "One Plus". The length() method returns the number of characters in the string. The string "One Plus" has 8 characters, including spaces. Therefore, the output of the code is 8.