✏️ Explanatory Question
String x[] = {"SAMSUNG", "NOKIA", "SONY", "MICROMAX", "BLACKBERRY"};
Give the output of the following statements:
- System.out.println(x[1]);
- System.out.println(x[3].length());
String x[] = {"SAMSUNG", "NOKIA", "SONY", "MICROMAX", "BLACKBERRY"};
Give the output of the following statements:
The output of System.out.println(x[1]); is NOKIA. x[1] gives the second element of the array x which is "NOKIA"
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());
}
}