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());
  1. 8
  2. 7
  3. 5
  4. 9
Answer

8

Reasona[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.