Results 1 to 2 of 2
- 07-16-2012, 12:55 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 8
- Rep Power
- 0
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?
- 07-16-2012, 01:38 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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.
Similar Threads
-
Errod in R.id, cannot find symbol variable id.
By aparnakm in forum AndroidReplies: 2Last Post: 02-09-2012, 06:32 AM -
Cannot find symbol variable
By xalebo in forum New To JavaReplies: 4Last Post: 11-28-2011, 07:09 PM -
cannot find symbol variable lines 24, 25, 44, 45, 63, 64? Help!
By ironman_777 in forum New To JavaReplies: 4Last Post: 12-25-2010, 01:17 PM -
Cannot find symbol variable - Why? I can.. ^^
By Mattedatten in forum New To JavaReplies: 4Last Post: 03-08-2010, 07:07 PM -
Cannot find symbol variable pD! I cant fix it!!!
By Addez in forum New To JavaReplies: 2Last Post: 09-17-2009, 08:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks