Write a Java program to calculate the average value of array elements


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. public class Javaexcercise {
  2. public static void main(String[] args) {
  3.  
  4. int[] numbers = new int[]{10, 20, 30, 60, 80, 100};
  5. int sum = 0;
  6. for(int i=0; i < numbers.length ; i++)
  7. sum = sum + numbers[i];
  8. //calculate average value
  9. double avg = sum / numbers.length;
  10. System.out.println("Average value of the array elements is : " + avg);
  11. }
  12. }

Result

java techstudy.org

     





Related Topics




Popular Posts