• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

while loop question

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Sheriff
Posts: 28411
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i assume i need other int's sum and average,
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 6
IntelliJ IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are on the right track with your approach. It just misses the sum and average calculation:

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And Welcome to JavaRanch Bobby Consaw
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic