Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

while loop question

 
Bobby Consaw
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys, great site,
java n00b here, question if you will, please.

given the following header: pubic void sumAndAverageRandom()

I need to write a method called sumAndAverageRandom that generates and displays 10 random numbers in the range 1-100. The method should also calculate the sum and average of the 10 random.
I can generate the 10 numbers, but Im lost on how to tie in sum and average in their also !
any help appreciated

thanks


 
Paul Clapham
Sheriff
Pie
Posts: 20764
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you were given 10 numbers, how would you calculate their sum and average if you didn't have a computer?

(Also you should declare your method public. The compiler is very serious and won't laugh at what you posted, but others might.)
 
Bobby Consaw
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i assume i need other int's sum and average,
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry i seriously did not understand the question. Happy if you have found out the answer. Else can you elaborate a little more.
If you really need the sum then you can add in the loop all the numbers you generate and div by 10 after the loop to get the average.
Paul - I dint understand your comment either

Regards,
Another Noooob
 
Bjoern Kimminich
Greenhorn
Posts: 6
Chrome IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are on the right track with your approach. It just misses the sum and average calculation:

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome to JavaRanch Bobby Consaw
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic