Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
302 views

Calculate Arithmetic Mean or Average in Java

The document provides code to calculate the arithmetic mean or average of numbers entered by a user in Java. The code first prompts the user to enter the number of values. It then uses a for loop to collect the values and calculate their sum. Finally, it divides the sum by the number of values to obtain the average and displays the result.

Uploaded by

sonam
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
302 views

Calculate Arithmetic Mean or Average in Java

The document provides code to calculate the arithmetic mean or average of numbers entered by a user in Java. The code first prompts the user to enter the number of values. It then uses a for loop to collect the values and calculate their sum. Finally, it divides the sum by the number of values to obtain the average and displays the result.

Uploaded by

sonam
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Calculate Arithmetic Mean or Average in Java

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 variableresponsible 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:

You might also like