Count The Number of Words in a Given String
String : Sateesh kumar
Count words: 2
import java.util.*;
class TokenizerDemo
{
public static void main(String args[])
{
String s="Hello students ,welcome to msk tutorials";
StringTokenizer st=new StringTokenizer(s," ");
int count=0;
while(st.hasMoreTokens())
{
count++;
st.nextToken()
}
System.out.pritln("Number of Words are"+ count);
}
}
String : Sateesh kumar
Count words: 2
more programs visit http://sateeshm.com/
No comments:
Post a Comment