Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pass array to method return average

 
Andrew Idzior
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have tried several different ways of coding for the same task. However, the same Out of Bounds exception keeps appearing. The goal here is to pass an array to a method and have the method return the average of the array. But I can't even get the method to print the average - let alone return it. Here's the code, what's wrong here!? ... Thanks for your time.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here you are trying to access an element with index one larger than the last one. Index of the last element is list.length - 1.

And please put your code inside code tags.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic