DetermineMean.java
This program was created to gather the mean of numbers inside an array. We call function mean and passing an array as a parameter to return a data type of double of the mean.
The code has been modified slightly and now uploaded to the site.
Code Snippet
/*
Author: ENTPRESTIGIOUS
Compiler: JDK 11.0.11 LTS
Link: https://edabit.com/challenge/W64jA8hmGCmjbR7Fb
*/
public class DetermineMean {
public static void main(String[] args){
int[] arr1 = {1, 0, 4, 5, 2, 4, 1, 2, 3, 3, 3};
int[] arr2 = {2, 3, 2, 3};
int[] arr3 = {3, 3, 3, 3, 3};
double result = mean(arr1);
double result2 = mean(arr2);
double result3 = mean(arr3);
System.out.println("The answer is: " + ((double)Math.round(result * 100.0) / 100.0));
System.out.println("The answer is: " + ((double)Math.round(result2 * 100.0) / 100.00));
System.out.println("The answer is: " + ((double)Math.round(result3 * 100.0) / 100.00));
}
public static double mean(int[] nums) {
double total = 0;
for (int i = 0; i < nums.length; i++){
total += nums[i];
}
double answer = total / (nums.length);
return answer;
}
}