# Java program to calculate mean of given numbers

Java Programming Java8Object Oriented Programming

Mean is an average value of given set of numbers. It is calculated similarly to that of the average value. Adding all given number together and then dividing them by the total number of values produces mean.

For Example

Mean of 3, 5, 2, 7, 3 is (3 + 5 + 2 + 7 + 3) / 5 = 4

## Algorithm

• Take an integer set A of n values.
• Add all values of A together.
• Divide result of Step 2 by n.
• The result is mean of A's values.

## Program

public class CaculatingMean {
public static void main(String args[]){
float mean;
int sum, i;
int n = 5;
int a[] = {2,6,7,4,9};
sum = 0;

for(i = 0; i < n; i++) {
sum+=a[i];
}
System.out.println("Mean ::"+ sum/(float)n);
}
}

## Output

Mean::5.6
Published on 26-Apr-2018 10:56:52
Advertisements