• Post Reply Bookmark Topic Watch Topic
  • New Topic

Average of sum in java  RSS feed

 
Amrit Kaur
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello can i know how you can get the average of first 100 numbers. i have the code of the sum of first 100,now how am i to get the average? can i have the average displayed only and not the other total sum? here is what i have done can i be helped please? and if i have to put the average in double only,not the sum..
 
Vasyl Lyashkevych
Ranch Hand
Posts: 70
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course you need to count all numbers and later divide them by quantity
 
Vasyl Lyashkevych
Ranch Hand
Posts: 70
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Vasyl Lyashkevych
Ranch Hand
Posts: 70
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vasyl Lyashkevych wrote:You need to exclude System.out.print() from cycle
 
salvin francis
Bartender
Posts: 1664
37
Eclipse IDE Google Web Toolkit Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vasyl,
Vasyl Lyashkevych wrote:Of course you need to count all numbers and later divide them by quantity

This is incorrect. You need to take a sum of all the numbers and then divide it by the quantity to get the average.

Btw, your program gives the following output:
5050.0
Which is not the average of first 100 numbers as asked by OP.


Hi Amrit,
Rather than writing code, can you explain how you would calculate the average of first 100 or lets say first 10 numbers on paper ?
 
Vasyl Lyashkevych
Ranch Hand
Posts: 70
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you're right, but I cannot edit posts. Alas, I couldn't correct my answer.
Have a nice time!
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Output obtained?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!