Count number of words in a string



Program

package com.candidjava;

class NoOfWords
{
	public static void main(String args[])
	{
		String string = "Welcome to Java Programming and Dotnet Programming";
		String[] wordsCount = string.split(" ");
		System.out.println("The Given String is:" + string + "\n");
		System.out.println("The Number Of Words in Given String is:" + wordsCount.length);
	}
}


Output

The Given String is:Welcome to Java Programming and Dotnet Programming

The Number Of Words in Given String is:7





Related Post

Comments


©candidjava.com