Java Array Average Program

  1. public class ArrayAverage{    
  2.     public static void main(String[] args) {    
  3.         double nums[]={1.0,2.3,3.4,4.5,40.5};    
  4.         double result=0.0;    
  5.         int i=0;    
  6.         for(i=0; i < nums.length; i++){    
  7.             result=result + nums[i];    
  8.         }    
  9.         System.out.println("Average is =" + result/nums.length);    
  10.     }    
  11. }