codescracker


java

Java Program to Calculate Arithmetic Mean



« Previous Program Next Program »


Calculate Arithmetic Mean or Average

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.

Java Programming Code to Calculate Arithmetic Mean or Average

Following Java Program ask to the user to enter "How many number he want to enter", then ask to enter all the numbers to calculate and display the arithmetic mean:

/* Java Program Example - Calculate Arithmetic Mean */
		
import java.util.Scanner;

public class JavaProgram
{
    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);
    }
}

When the above Java Program is compile and executed, it will produce the following output:

Java Program calculate average of number

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test