Write a Java Program to Calculate Average Using Arrays

Java Program to Calculate Average Using Arrays

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Java Program to Calculate Average Using Arrays
Java Program to Calculate Average Using Arrays

Write a Java Program to Calculate Average Using Arrays

PROGRAM: Java Program to Calculate Average Using Arrays

/*Java Program to Calculate Average Using Arrays*/

public class Average {

public static void main(String[] args) {
double[] numArray = { 45.3, 67.5, -45.6, 20.34, 33.0, 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);
}
}

Leave a Reply

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