Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. private static void average(int... amount) {
  2. double average = (double) amount[0];
  3. for (double i = 1; i < amount.length; i++) {
  4. System.out.printf("average: %d%n", (int) average);
  5. double newWeight = (i + 1d) / i;
  6. double newAverage = average / newWeight;
  7. double thisAverage = (amount[(int)i]) / (i+1d);
  8. average = newAverage + thisAverage;
  9. }
  10. System.out.printf("average: %d%n", (int) average);
  11. }
  12.  
  13. public void test(int[] values) {
  14. BigDecimal sum = BigDecimal.ZERO;
  15. for (int count = 0; count < values.length; count++) {
  16. sum = sum.add(new BigDecimal(values[count]));
  17. System.out.printf("%s/%d = %s%n", sum, (count+1), sum.divide(new BigDecimal(count+1)));
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement