ICSE Class 10 Computer Applications Question 14 of 30

Solved 2024 Question Paper ICSE Class 10 Computer Applications — Question 19

Back to all questions
19
Question

Question 1(xix)

What is the output of the Java code given below?

String color[] = {"Blue", "Red", "Violet"};
System.out.println(color[2].length());
  1. 6
  2. 5
  3. 3
  4. 2
Answer

6

Reason — The given Java code declares and initializes a String array color with three elements. The array elements are:

  • color[0] = "Blue"
  • color[1] = "Red"
  • color[2] = "Violet"

The method length() returns the number of characters in the string "Violet".