I'm writing a program that displays the Maximum, Minimum, and average of an array
So far I have methods for the max and min but not for the average.
My code:
class Test
{
public static void main(String[] args)
{
int[] arr = {5,12,-3,7,3,22,31,2,16,56};
System.out.println(minValue(arr));
System.out.println(maxValue(arr));
System.out.println(avgValue(arr));
}// end of Main
// Array Methods
public static int minValue(int[] nums)
{
int minValue = nums[0];
for(int i=1;i < nums.length; i++){
if( nums[i] < minValue){
minValue = nums[i];
}
}
return minValue;
}
public static int maxValue(int[] nums)
{
int maxValue =nums[0];
for(int i=1;i < nums.length ;i++){
if( nums[i] > maxValue){
maxValue = nums[i];
}
}
return maxValue;
}
public static int avgValue(int[] nums)
{
int temp = 4;
return temp;
}
}// end fo class
Right now the method to find the average is filled with a placeholder integer that always returns "4"
How would I write a message to find the average of my array?