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

    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
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    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 R.id, cannot find symbol variable id.
    By aparnakm in forum Android
    Replies: 2
    Last Post: 02-09-2012, 07:32 AM
  2. Cannot find symbol variable
    By xalebo in forum New To Java
    Replies: 4
    Last Post: 11-28-2011, 08:09 PM
  3. Replies: 4
    Last Post: 12-25-2010, 02:17 PM
  4. Cannot find symbol variable - Why? I can.. ^^
    By Mattedatten in forum New To Java
    Replies: 4
    Last Post: 03-08-2010, 08: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, 09: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
  •