package com.swain.cell;
import java.util.StringTokenizer;
public class CountWords {
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
        String st="how to count word in java?";
        int count=0;
        StringTokenizer stk=new StringTokenizer(st," ");
        while(stk.hasMoreTokens()){
            String token=stk.nextToken();
            count++;
        }
        System.out.println("Number of words are: "+count);
 }
}
No comments:
Post a Comment