Java Program to Calculate Average of n Numbers Source Code

Java Program to Calculate Average of n Numbers; The result of the sum of the numbers divided by the count of the numbers being averaged is the average.

This article has project files included, just scroll down and click the download button and you can edit the project source code for free.

For instance: 1,2,3,4,5

Total number of elements = 5
The sum of all elements = 1+2+3+4+5 =15

Sample Code:

//How to calculate an average of numbers: Sample Code      

package calculate_average_of_n_numbers;
import java.util.Scanner;

public class Calculate_Average_of_n_Numbers {
    
    public static void main(String[] args) {
        int n, count = 1;
        float xF, averageF, sumF = 0;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the value of n");
        n = sc.nextInt();
        while (count <= n) {
            System.out.println("Enter the " + count + " number?");
            xF = sc.nextInt();
            sumF += xF;
            ++count;
        }
        averageF = sumF / n;
        System.out.println("The Average is " + averageF);
    }

}

Sample Code Output:

//How to calculate an average of numbers: Sample Code Output

Enter the value of n

3
Enter the 1 number?
4
Enter the 2 number?
5
Enter the 3 number?
6
The Average is 5.0

Java program to find the average of n numbers importance?

Averages are used to represent a large number range with a single number. It is a graphical representation of all the numbers in the data set. So it is importance to present data sets.

How to find average in Java: Method

The mean, also known as the average, is calculated by adding all of the scores and dividing the total by the number of scores.

About the Project

The arithmetic mean is calculated by adding a group of numbers and then dividing by the number of those numbers.

The average of 2, 3, 3, 5, 7, and 10 is 30 divided by 6, which equals 5.

Project Details and Technology

Project Name:Java Program to Calculate Average of n Numbers Source Code
AbstractThe Java Program to Calculate Average of n Numbers is a basic system project where having function of calculating average n Numbers.
Language/s Used:Java
Java version (Recommended):8
Database:N/A
Type:Desktop Application
Developer:Tedmar Enoria
Updates:0

To start executing a Java Program to Calculate the Average of n Numbers, make sure that you have  NetBeans IDE or any platform of code editor installed on your computer.

How to calculate an average of numbers: Procedure

Time needed: 3 minutes

How to calculate an average of numbers: Steps how to run the project

  • Step 1: Download Source Code

    To get started, find the downloaded source code file below and click to start downloading it.

    Java Program to Calculate Average of n Numbers

  • Step 2: Extract File

    Navigate to the file’s location when you’ve finished downloading it and right-click it to extract it.

    Java Program to Calculate Average of n Numbers extract

  • Step 3: Run the project

    Next, open NetBeans IDE and click open project, and choose your download.

    Java Program to Calculate Average of n Numbers open projects

  • Step 4: Run the project.

    Next, right-click the project folder and click run.

Download the Source Code below

Summary

For those Web developers interested in learning more about web apps, this system is a fully functional project.

Inquiries

If you have any questions or comments on the project, please leave a comment below.

Leave a Comment