MargretP

Calculate average of array data

Oct 24th, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.32 KB | None | 0 0
  1. public class Demo
  2. {
  3.    public static void main(String[] args) {
  4.       double[] numbers = {1.2, 4.3, 6.5, 3.7, 4.8};
  5.      
  6.       double total = 0;
  7.       for (double d : numbers) {
  8.          total += d;
  9.       }
  10.      
  11.       double average = total / numbers.length;
  12.       System.out.println("Average: " + average);
  13.    }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment