Java Program to Count Number of Words in Given String

 Java Program to Count Number of Words in Given String

//Java Program to Count Number of Words in Given String

class WordCount

{

public static void main(String[] args)

{

String str="hello this is shweta, i am from bihar";

int count=0;

for(int i=0;i<str.length();i++){

if(str.charAt(i)==' '){

count++;

}

}

System.out.println(count);

System.out.println("So , total number of words are :"+(count+1));

}

}

Comments

Popular posts from this blog

Software Engineering PPT

ERP Software Links

Include Tag JSP