Computer Applications
What will be the output of the following code?
String a[] = {"MI", "Samsung", "Micromax", "One Plus"};
System.out.println(a[3].length());
- 8
- 7
- 5
- 9
Java String Handling
8 Likes
Answer
8
Reason — a[3] refers to the fourth element of the array, which is "One Plus". The length() method returns the number of characters in the string. The string "One Plus" has 8 characters, including spaces. Therefore, the output of the code is 8.
Answered By
3 Likes
Related Questions
The parameters that are passed to the method when it is invoked are called
- formal parameters
- actual parameters
- informal parameters
- void parameters
Give the output of Math.sqrt(x); when x = 9.0.
- 3
- 3.0
- 3.00
- All of these
Polymorphism is broadly used in implementing ……………
- inheritance
- encapsulation
- abstraction
- literals
Give the output of the following
switch (x) { case 'M' : System.out.print ("Microsoft Teams"); break; case 'G': System.out.print ("Google Meet"); default: System.out.print("Any Software"); break; case 'W': System.out.print("Web Ex"); break; }when x = 'g'
- Google Meet
- Any Software
- Google Meet
Any Software - Web Ex