Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

no of words in a string in java

public class wordsinstring
{ 
    public static void main(String args[]) 
    { 
        String str="India is a really fast growing economy";
        System.out.println(str);
        int count=1;
        
        int len=str.length();
        for(int i=0;i<len;i++)
        {
          if(str.charAt(i)==' ')
          {
            count++;
          }
        }
        System.out.println("The string contains "+count+ " words.");
        
        
    } 
}
 
PREVIOUS NEXT
Tagged: #words #string #java
ADD COMMENT
Topic
Name
2+5 =