Computer Science, asked by BrainlyProgrammer, 2 months ago

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 anindyaadhikari13
8

\texttt{\textsf{\large{\underline{Answer}:}}}

  • 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.

\texttt{\textsf{\large{\underline{Learn More}:}}}

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 purveshKolhe
5

0 is your answer as space is also counted here and arrays start at 0. Therefore, the length will be 0.

Similar questions