WWW Programiz Com Java Programming Examples Average Arrays
WWW Programiz Com Java Programming Examples Average Arrays
Using Arrays
To understand this example, you should have the knowledge of the following Java
programming topics:
Java Arrays
Output
In the above program, the numArray stores the floating-point values whose average
is to be found.
Then, to calculate the average , we need to first calculate the sum of all elements in
the array. This is done using a for-each loop in Java.
Explore our developer-friendly HTML to PDF API Printed using PDFCrowd HTML to PDF
average = sum of numbers / total count
Finally, we print the average using format() function so that we limit the decimal
points to only 2 using "%.2f"
Related Examples
Java Example
Java Example
Java Example
Explore our developer-friendly HTML to PDF API Printed using PDFCrowd HTML to PDF
Calculate the Power of a Number
Java Example
Explore our developer-friendly HTML to PDF API Printed using PDFCrowd HTML to PDF