Results 1 to 2 of 2
  1. #1
    walsby14 is offline Member
    Join Date
    Jul 2012
    Rep Power

    Default 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?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power

    Default 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

  1. Errod in, cannot find symbol variable id.
    By aparnakm in forum Android
    Replies: 2
    Last Post: 02-09-2012, 06:32 AM
  2. Cannot find symbol variable
    By xalebo in forum New To Java
    Replies: 4
    Last Post: 11-28-2011, 07:09 PM
  3. Replies: 4
    Last Post: 12-25-2010, 01:17 PM
  4. Cannot find symbol variable - Why? I can.. ^^
    By Mattedatten in forum New To Java
    Replies: 4
    Last Post: 03-08-2010, 07:07 PM
  5. Cannot find symbol variable pD! I cant fix it!!!
    By Addez in forum New To Java
    Replies: 2
    Last Post: 09-17-2009, 08:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts