What is the output of the Java code given below?

ICSE Class 10 Computer Applications PYQ · 2024 Paper · Section A

1(xix)1 Mark · 2024 · Section A · 2024 Paper

What is the output of the Java code given below?

String color[] = {"Blue", "Red", "Violet"};
System.out.println(color[2].length());
Show SolutionHide Solution↓

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".

← Previous questionNext question →

Browse the free Computer Applications sample bank