Count Words
this is a sample string
5
public class Solution {
public static int countWords(String str) {
//Your code goes here
int l=str.length();
int c=0;
str=" "+str;
for(int i=0;i<l;i++)
{
char ch=str.charAt(i);
if(ch==' ')
{
c++;
}
}
return c;
}
}
Comments
Post a Comment