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
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

Sum and Average of input numbers

Greenhorn
Posts: 6
• Number of slices to send:
Optional 'thank-you' note:
please help me create a simple program that can input number from 1 to n. and display the numbers which input by the user and also display the sum and average of it.
ex.
1 2 3 4 5 6 7 8 9 10

the sum numbers of 12345678910 is 55

the average number of 12345678910 is ______,

thanks for you help.

Bartender
Posts: 3648
16
• Number of slices to send:
Optional 'thank-you' note:
We here at the Ranch is not a code mill.

What have you tried? Or are you stuck getting started?

Lord Jeffrey Mina
Greenhorn
Posts: 6
• Number of slices to send:
Optional 'thank-you' note:

Lord Jeffrey Mina
Greenhorn
Posts: 6
• Number of slices to send:
Optional 'thank-you' note:
for example:
enter a number:
1
2
3
4
5
the sum of 12345 is: 15.0
the average of 15 is: 3.0

Marshal
Posts: 79231
377
• Number of slices to send:
Optional 'thank-you' note:
And what is the problem? Apart from the main method being far too long, that is.

Sheriff
Posts: 5555
326
• Number of slices to send:
Optional 'thank-you' note:
So for each double you read in with the Scanner you need to keep a record of this in some sort of List structure. Then when you come to print out the results you can include each element in that List in the output.

How do you think you might go about doing that?

Campbell Ritchie
Marshal
Posts: 79231
377
• Number of slices to send:
Optional 'thank-you' note:
Aaaaaaaaah, so that is it. TC has given you the answer.