Can anyone teach me on how to create a program that counts spaces entered in a string.....

Recommended Answers

All 3 Replies

Loop through a string and for every char that is a whitespace increment a counter.

The method that di2daer is referring to can be found here:

java.lang.String

String msg = "place message here";
int cntr = 0;
for i = 0 to  msg.size; increment i by 1 
{
     if msg.charAt(i) is equal to a white space or == ' ' then 
     increment cntr by 1;
}

System.out.print(cntr);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.