Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Exercise - Count Words

Write a method which counts the number of words in a string.

Tutorial Details:

Signature
public static int countWords(String s)
Note: This is declared static because it is doesn't depend on instance variables from the class it is defined in. It's declared public only because it might be generally useful.

Extensions
A better definition of "word" would make this better. For example, non-alphabetics between words should only count if they include at least one blank so that contractions like "don't" aren't counted as two words.


 

Rate Tutorial:
http://www.roseindia.net/java/java-tips/data/strings/q-pr-string-using-loops/q-pr-countwords.shtml

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Exercise - Count Words

View Tutorial:
Exercise - Count Words

Related Tutorials:

The battle of the container frameworks: which should you use? - JavaWorld - January 1999
The battle of the container frameworks: which should you use? - JavaWorld - January 1999
 
Java Tip 71: Use dynamic messaging in Java - JavaWorld - April 1999
Java Tip 71: Use dynamic messaging in Java - JavaWorld - April 1999
 
Design networked applications in RMI using the Adapter design pattern
Design networked applications in RMI using the Adapter design pattern
 
Speed up listener notification - JavaWorld February 2000
Speed up listener notification - JavaWorld February 2000
 
The Lucene search engine: Powerful, flexible, and free - JavaWorld September 2000
The Lucene search engine: Powerful, flexible, and free - JavaWorld September 2000
 
Matchmaking with regular expressions - JavaWorld July 2001
Matchmaking with regular expressions - JavaWorld July 2001
 
Flex your grid layout
Flex your grid layout
 
Use XML data binding to do your laundry
Use XML data binding to do your laundry
 
Eclipse casts shadows
Eclipse casts shadows
 
Java Tip 132: The taming of the thread
Java Tip 132: The taming of the thread
 
roots of constants classes
roots of constants classes
 
Dictionary and Thesaurus API for Java
What is the Dictionary and Thesaurus API for JavaTM? The Dictionary and Thesaurus API for Java is a standard-based class library for accessing a dictionary and thesaurus using Java. It provides programming access to wordbook data from the Java programm
 
FindBugs, Part 2: Writing custom detectors
FindBugs, Part 2: Writing custom detectors How to write custom detectors to find application-specific problems In the first article in this series, I showed you how to set up and execute FindBugs. Now we'll take a look at FindBugs' most powerful fea
 
NIO Tutorials
NIO Tutorials Introduction In the words of Gregory Pierce, "NIO is one of the most important but least understood APIs that came along for the ride with JDK1.4". Couldn't have put it better myself :). The aim of this series of articles is to help you
 
From Writing Programs to Creating Compilers
From Writing Programs to Creating Compilers In this article we build a simple compiler that augments Java with tasks (independent blocks of code that execute in parallel), thus creating a new language called AJ that well supports the programming of syste
 
Network Programming with JavaTM 2 Platform, Standard Edition 1.4 (J2SETM)
This article provides an overview of the new features and enhancements in the Java 2 Platform, Standard Edition 1.4 (J2SE), and shows you how to use them effectively.
 
Welcome to Free search engine secrets: webmaster's guide to search engine registration!
Welcome to Free search engine secrets: webmaster's guide to search engine registration! Welcome To Webmaster's Guide T his site is dedicated to Web related services. Here you can find tools and suggestions to promote your sites to several search
 
Creating EJB clients using the Eclipse Rich Client Platform
This article shows how to build a sample EJB client using the Eclipse Rich Client Platform (RCP), which has become increasingly popularity due to its extensible nature.
 
one-jar
One-JAR is a simple solution to a vexing problem in Java: how to distribute an application as a single jar-file, when it depends on multiple other jar-files. One-JAR uses a custom classloader to discover library jar files inside the main jar.
 
Urchin RSS Aggregator
Urchin is a Web based, customisable, RSS aggregator and filter. It\'s primary purpose is to allow the generation of new RSS feeds by running queries against the collection of items in the Urchin database.
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.