• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sum and Average of input numbers  RSS feed

 
Lord Jeffrey Mina
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.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • 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
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • 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.
 
Tim Cooke
Marshal
Posts: 4048
239
Clojure IntelliJ IDE Java
  • 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: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aaaaaaaaah, so that is it. TC has given you the answer.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!