Question for Begginners!!
Predict the output:-
class check {
public static void main (String ar []){
String k="";
System.out.println(k.length());
}
}
Difficulty Level:Easy
•Don't be greedy of points
•Good luck!!
Answers
Answered by
8
- Output for the cøde is - 0
- length( ) fuñction returns the length of string. Here, the string k is empty. So, length( ) returns 0.
String – A string is an object that represents collection of characters.
Some string fuñctions –
- charAt( ): Returns the character from the string at specific index. Returns error if the index is out of range.
- toLowerCase( ): Returns new string converted to lower case.
- toUpperCase( ): Returns new string converted to upper case.
- compareTo( ): Compares two strings lexicographically.
- contains( ): Check whether a string contains a specific set of characters.
- endswith( ): Check whether a string ends with another string.
Answered by
5
0 is your answer as space is also counted here and arrays start at 0. Therefore, the length will be 0.
Similar questions
English,
1 month ago
Math,
1 month ago
English,
1 month ago
Computer Science,
2 months ago
Physics,
2 months ago
Computer Science,
10 months ago