- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to calculate the average of numbers in Java
An average of a set of numbers is their sum divided by their quantity. It can be defined as −
average = sum of all values / number of values
Here we shall learn how to programmatically calculate average.
Algorithm
1. Collect integer values in an array A of size N. 2. Add all values of A. 3. Divide the output of Step 2 with N. 4. Display the output of Step 3 as average.
Example
public class AverageOfNNumbers { public static void main(String args[]){ int i,total; int a[] = {0,6,9,2,7}; int n = 5; total = 0; for(i=0; i<n; i++) { total += a[i]; } System.out.println("Average ::"+ total/(float)n); } }
Output
Average ::4.8
- Related Articles
- Java program to calculate the product of two numbers
- Java Program to Calculate the Sum of Natural Numbers
- Java program to calculate mean of given numbers
- Java program to find the average of given numbers using arrays
- C++ Program to Calculate Average of Numbers Using Arrays
- Golang Program to Calculate the Average of Numbers in a Given List
- Java program to calculate mode in Java
- Java Program to calculate Sum of squares of first n natural numbers
- Java program to calculate the percentage
- Java Program to Calculate the Compound Interest
- Java program to calculate the power of a number
- Java Program to Calculate the Execution Time of Methods
- Java Program to Calculate the intersection of two sets
- Calculate average of numbers in a column MySQL query?
- JAVA Program to Calculate Length of Chord of the Circle

Advertisements