String x[] = {"SAMSUNG", "NOKIA", "SONY", "MICROMAX", "BLACKBERRY"};

Give the output of the following statements:

  1. System.out.println(x[1]);
  2. System.out.println(x[3].length());

Views 10

Answer:

  1. The output of System.out.println(x[1]); is NOKIA. x[1] gives the second element of the array x which is "NOKIA"

  2. The output of System.out.println(x[3].length()); is 8. x[3].length() gives the number of characters in the fourth element of the array x which is MICROMAX.


public class Main {
    public static void main(String[] args) {
        String x[] = {"SAMSUNG", "NOKIA", "SONY", "MICROMAX", "BLACKBERRY"};

        // Output the element at index 1
        System.out.println(x[1]);

        // Output the length of the string at index 3
        System.out.println(x[3].length());
    }
}

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.