cannot find symbol - variable length
public static double averageLength()
{
int count = 0; // to hold the number of words input
int numberOfCharacters = 0; // to hold the total number of characters
String word = ""; // to hold each word as it is input
{
while (!word.equals("*")) // loop until the word input is "*"
word = OUDialog.request("Please enter next word"); //input the next word
numberOfCharacters = numberOfCharacters + word.length; // add its length onto the number of characters
count++; // add 1 to the number of words
}
return numberOfCharacters / count; // calculate the average by diving the number of characters
// by the number of words and return the average
}
when i try and compile this i get the error message cannot find symbol variable length. But i'm not sure why, I thought .length was a standard method of finding the length of a word?
Re: cannot find symbol - variable length
All the String methods are listed here.
Also, as you have used it length would have to be an instance variable, rather than a method. Maybe you are confusing things with an array which does have a length.