• Post Reply Bookmark Topic Watch Topic
  • New Topic

For Loop  RSS feed

 
James Nobles
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I get , in my for loop, where the value that is caught in the for loop in returned so I can use it in the method at the bottom of my syntax?

 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your for loop isn't doing anything (and the initialization of "average" isn't legal) so I'm not sure what value you are talking about. If it's "average" then you are returning it already so you just call the getAverage() method and assign the returned value to a local variable or use it directly.

BTW Your toString() method is using "Grades" - the capital first letter implies it is a class name but you are using it as if it is an array in the first 4 lines so I guess it's a variable. The problem is you are then calling methods on Grades which aren't legal for an array, I suspect they are supposed to be called on one of the elements in the array.
I think it would help if you showed the whole class file and explained what your code is trying to achieve.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!