Re: Unknown number of inputs
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Wed, 31 Jan 2007 10:53:26 -0500
f2prateek wrote On 01/30/07 01:14,:
I want to make a program to print the average of the numbers entered
by the user,but how do i accept the numbers from the user,if the
number of numbers enetred by him or not known to me??
Various people have suggested ways to store a bunch
of numbers in an array or ArrayList or Vector or whatever.
That's silly.
I'm going to read you a bunch of numbers -- you don't
know exactly how many -- and at some point I'll ask you to
tell me the average of the numbers you've been read. Can
you do the job without keeping a record of each individual
number?
Hint: Consider an even more complicated problem (as is
sometimes the case, a more general problem may be simpler
than a specific problem, and may offer a clue to solving
it.) After you've reported an average, I'll read you some
more numbers and then ask for the average of all the numbers
to date. And then more, and then more -- or, to look at it
another way, I'll read you a bunch of numbers and interrupt
myself every now and then to ask for the average thus far.
Can you do the job without recording every individual number?
--
Eric.Sosman@xxxxxxx
.
- References:
- Unknown number of inputs
- From: f2prateek
- Unknown number of inputs
- Prev by Date: Re: JSP won't compile... error contains no info......
- Next by Date: JavaMail question..
- Previous by thread: Re: Unknown number of inputs
- Next by thread: Is this recursion?
- Index(es):
Relevant Pages
|