KnowledgeBoat Logo
|

Computer Applications

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

Java String Handling

8 Likes

Answer

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.

Answered By

3 Likes


Related Questions