Sunday, 20 July 2014

Java Program to count the number of words in a given text

Program

import java.lang.*;
import java.util.*;
class frequency
{
  public static void main(String args[])
  {
    Scanner s=new Scanner(System.in);
    System.out.println("Enter line of text ");
    String str=s.nextLine();
    StringTokenizer s1=new StringTokenizer(str," ");
    int n= s1.countTokens();
    System.out.println("Frequency count of given text is "+n);
  }
}


Result

Enter line of text

This is the Java program for frequency count

Frequency count of given text is 8

No comments:

Post a Comment