File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes while loop question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "while loop question" Watch "while loop question" New topic

while loop question

Bobby Consaw

Joined: Jul 04, 2011
Posts: 2
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


Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

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

Joined: Jul 04, 2011
Posts: 2
i assume i need other int's sum and average,
John Jai

Joined: May 31, 2011
Posts: 1776
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

Another Noooob
Bjoern Kimminich

Joined: Jul 04, 2011
Posts: 6

You are on the right track with your approach. It just misses the sum and average calculation:

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

And Welcome to JavaRanch Bobby Consaw
I agree. Here's the link:
subject: while loop question
It's not a secret anymore!