Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Sum and Average of input numbers

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Please input a number:
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
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Lord Jeffrey Mina
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me display the numbers which is input by the user. thanks
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: 70353
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what is the problem? Apart from the main method being far too long, that is.
 
Sheriff
Posts: 4889
317
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 70353
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aaaaaaaaah, so that is it. TC has given you the answer.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic