Question
Im am currently having trouble find the above average and below average values in an array. I currently found the average of the array but
Im am currently having trouble find the above average and below average values in an array. I currently found the average of the array but i don't understand how to find them. Im expected to find that there is 8 values that are above the average and 7 below.
My code:
public class Array17B
{
public static void main(String[] args)
{
int[]myArray = {45, 38, 27, 46, 81, 72, 56, 61, 20, 48, 76, 91, 57, 35, 78};
int size = myArray.length;//length
System.out.print("Length of the array: "+size);
System.out.println();
int max = myArray[0];
int index1 = 0;
int index2 = 0;
for (int i = 1; i
{
if (myArray[i] > max)
{
max = myArray[i];
index1 = i;
}
}
int sum = 0;
for (int i = 0; i
sum+=myArray[i];
double total = 0;
double average;
for (int i = 0; i
total+=myArray[i];
average = total/myArray.length;
int min = myArray[0];
for (int i = 1; i
{
if (myArray[i]
{
min = myArray[i];
index2 = i;
}
}
System.out.print(" Max value of array: "+max);
System.out.print(" Index of max value of the array: "+index1);
System.out.println();
System.out.print(" Sum of array: "+sum);
System.out.println();
System.out.print(" Min value of array: "+min);
System.out.print(" Index of min value of the array: "+index2);
System.out.println();
System.out.print(" Average of value of the array: "+average);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started