How to calculate average of all numbers of array in Java

In the last article, I teach you how to calculate the sum of all numbers in a given array and in this article, we'll go one more step. This time, you need to write a program to calculate the average of all numbers from a given array, for example, you will be passed salaries of Java developers in different states in the USA and you need to calculate the average salary of Java developer in the USA. The example of average salaries of Java developer is more interesting because everybody wants to know how much Java developers make, isn't it? Anyway, coming back to the requirement of the program, The array will contain integers, which can be both positive and negative, so you must handle them. Your program should also be robust e.g. it should not break if you pass empty array or null. In these case either you can throw IllegalArgumentException  as returning any other number will be ambiguous.
Read more »