Answer:
The method is as follows:
public static double average(int [] arrs){
double sum = 0,avgNum;
for(int i = 0;i<arrs.length;i++){
sum+=arrs[i];
}
avgNum = sum/arrs.length;
System.out.printf("The average of all numbers is %.2f\\", avgNum);
return avgNum;
}
Step-by-step explanation:
This defines the method
public static double average(int [] arrs){
This declares sum and avgNum as double; sum is then initialized to 0
double sum = 0,avgNum;
This iterates through the array
for(int i = 0;i<arrs.length;i++){
This adds up the array elements
sum+=arrs[i]; }
This calculates the average
avgNum = sum/arrs.length;
This prints the average to 2 decimal places
System.out.printf("The average of all numbers is %.2f\\",
avgNum);
This returns the average to main
return avgNum; }