JAVA STRING TOKENIZER

JAVA STRING TOKENIZER

/*counting word in String using StringTokenizer */
import java.util.*;
public class StringTokenizerx //extends Object implements Enumeration<Object>
{
    public static int countWordsUsingStringTokenizer(String sentence)
    {
        if(sentence==null || sentence.isEmpty())
        {
            return (0);
        }
        StringTokenizer tok = new StringTokenizer(sentence);
        return (tok.countTokens());
    }
    
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.print("\nEnter : ");
        String input;
        input=sc.nextLine();
        int len=countWordsUsingStringTokenizer(input);
        System.out.println("\nTotal Number of Words Are: "+len);

    }
}

Comments

Popular posts from this blog

SAME NAME IN CLASS METHOD AND CONSTRUCTOR

PALINDROME NUMBER

FIBONACCI SERIES