Computer Applications
What is the output of the Java code given below?
String color[] = {"Blue", "Red", "Violet"};
System.out.println(color[2].length());
- 6
- 5
- 3
- 2
Java Arrays
ICSE 2024
6 Likes
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"
.
Answered By
2 Likes
Related Questions
The correct statement to create an object named mango of class fruit:
- Fruit Mango= new fruit();
- fruit mango = new fruit();
- Mango fruit=new Mango();
- fruit mango= new mango();
Assertion (A): Static method can access static and instance variables.
Reason (R): Static variable can be accessed only by static method.
- Assertion and Reason both are correct.
- Assertion is true and Reason is false.
- Assertion is false and Reason is true.
- Assertion and Reason both are false.
Which of the following mathematical methods returns only an integer?
- Math.ceil(n)
- Math.sqrt(n)
- Math.floor(n)
- Math.round(n)
Write Java expression for: