It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Pass array to method return average Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pass array to method return average" Watch "Pass array to method return average" New topic
Author

Pass array to method return average

Andrew Idzior
Greenhorn

Joined: Sep 24, 2012
Posts: 1
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

Joined: Jun 19, 2010
Posts: 825
    
    5


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.


The quieter you are, the more you are able to hear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pass array to method return average