Sunday, March 31, 2013

Average an Array of Values



package com.swain.cell;

public class AverageOfArrayValues {
       public static void main(String args[]) {

              double nums[] = { 10.1, 11.2, 12.3, 13.4, 14.5 };// Here We Define Array
              double result = 0; // Result variable to Store the sum of array of
                                                // values
              int i;

              for (i = 0; i < 5; i++)
                     result = result + nums[i]; // addition of Values
              System.out.println("Average is " + result / 5);
       }

}

No comments:

Post a Comment

How ChatGPT can Benefit Coding: Your Guide to Leveraging an AI Language Model

 Introduction: Hello, coders! Welcome to this blog post on how ChatGPT, an AI language model, can benefit your coding skills and projects. A...