# Infolet

### Java Program to Find the Mean / Average of Many Numbers

This is a simple java console program to find the mean of numbers. Using this program, you can find the mean of many numbers. At first, this program will accept the total number of numbers. After this, program will accept all numbers from user. Then program will find the mean using following mathematical formula.

Mean = Sum of total numbers of elements / number of elements.
Example: If number are 1,2,3.
Here sum is = 1+2+3 = 6
Here number of elements are 3
So that Mean is = 6 / 3 = 2

Here class name is ‘mean’, so you should save your file with name ‘mean.java’.
[Lean here how to create, compile and run a java application program here.]

Program code:

 import java.io.*; class mean {  int num;  double sum = 0;  double result; void findmean() throws IOException {   BufferedReader Br = new BufferedReader(new InputStreamReader(System.in));   System.out.print("\n Mean of how many numbers : ");     num = Integer.parseInt(Br.readLine()); int nums[] = new int[num+1];   for(int i = 1;i<=num;i++)   {    System.out.print("\n Enter " + i + " number : ");    nums[i]= Integer.parseInt(Br.readLine());    sum = sum + nums[i];   }   result = sum / num;   System.out.print("\n  Mean of above numbers is :  " +  result ); }  public static void main(String s[]) throws IOException   {    mean mn = new mean();    mn.findmean();   } }

Sample output:

# Subscribe To Get Articles On Your Inbox!

#### Responses

0 Respones to "Java Program to Find the Mean / Average of Many Numbers"