Write a Java Program to Calculate Arithmetic Mean of N numbers

By | 07.02.2017

Java Program to Calculate Arithmetic Mean of N numbers


Java Program to calculate the arithmetic mean of some numbers in Java Programming, you have to ask to the user to enter number size then ask to enter the numbers of that size to perform the addition, then make a variable responsible for the average and place addition/size in average, then display the result on the output screen.

SOURCE CODE ::

 

import java.util.Scanner;

public class Arithmetic_Mean
{
    public static void main(String args[])
    {
        int n, i, sum=0, armean;
        int arr[] = new int[50];
        Scanner scan = new Scanner(System.in);
                
        System.out.print("How many Number you want to Enter ? ");
        n = scan.nextInt();
                
        System.out.print("Enter " +n+ " Numbers : ");
        for(i=0; i<n; i++)
        {
            arr[i] = scan.nextInt();
            sum = sum + arr[i];
        }
                
        armean = sum/n;
                
        System.out.print("Arithmetic Mean = " +armean);
    }
}

 

OUTPUT ::

 

How many Number you want to Enter ? 6
Enter 6 Numbers : 4
1
8
3
5
6
Arithmetic Mean = 4

 

4.5 2 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments