I can't get this program to count the spaces, I have a feeling there is a logic error in the loop, but I am too inexperienced to figure it out myself. Any tips?
System.out.print("Enter a string: ");
String myString = keyboard.next();
int numBlanks = 0;
//find string length
int length = myString.length() - 1;
System.out.println("length " + length);
for(int sequence = 0; sequence >= length; ++sequence);
{
if(myString.charAt(length)==' ')
{
numBlanks += 1;
length -= length;
}
else
length -= length;
}