HomeJavaJava Program to Calculate Average Using Arrays

Java Program to Calculate Average Using Arrays

In this Java program, we will learn how to Calculate Average Using Arrays in your Java program

How to Calculate Average Using Arrays using JAVA? 

Example 1: 

RUN CODE SNIPPET
public class Main 
 { 
    public static void main(String[] args) 
     { 
        double[] numArray = { 54.5, 57.6, -54.9, 100, 99, 45.6 }; 
        double sum = 0.0; 
        for (double num: numArray)  
        { 
           sum += num; 
        } 
        double average = sum / numArray.length; 
        System.out.format("The average is: %.2f", average); 
    } 
}

OUTPUT 

The average is: 50.30

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Java is a popular programming language that is used to develop a wide range of applications. If you are a...
  • Java
  • March 6, 2023
Java is a programming language and computing platform that is used to create various types of applications. It is used...
  • Java
  • March 6, 2023
In this post, you’ll learn how to download and install JUnit in Eclipse so that you can use in your...
  • Java
  • October 9, 2022