3 Replies - 2888 Views - Last Post: 25 May 2013 - 04:45 AM Rate Topic: -----

#1 java_dummy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 24-May 13

Average Word Length function

Posted 24 May 2013 - 03:06 PM

I am trying to figure out how to do this averagewordLength function but I have no idea how to add the x from the double into my for loop.
this is what i have so far
 static double averageWordLength(ArrayList<String> text) {
     double x;
     for(int I = 0; I<text.size(); I++){  

Is This A Good Question/Topic? 0
  • +

Replies To: Average Word Length function

#2 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3744
  • View blog
  • Posts: 17,121
  • Joined: 20-September 08

Re: Average Word Length function

Posted 24 May 2013 - 03:14 PM

Clue

x += text.get(I).length();

Was This Post Helpful? 1
  • +
  • -

#3 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Average Word Length function

Posted 24 May 2013 - 09:00 PM

View Postjava_dummy, on 24 May 2013 - 06:06 PM, said:

but I have no idea how to add the x from the double

What a double has to do with a length() function that counts the number of characters in a String ?
Seriously You think you can have a word with a length of 3.14159 unless, may be it is "PI" ??? :)
Was This Post Helpful? 0
  • +
  • -

#4 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3744
  • View blog
  • Posts: 17,121
  • Joined: 20-September 08

Re: Average Word Length function

Posted 25 May 2013 - 04:45 AM

Quote

What a double has to do with a length() function that counts the number of characters in a String ?
Actually it's quite apt when you consider the other line of code (which i didn't supply)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1