Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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);

}

}

image text in transcribed
Expected Output: Length of the array: 15 Max value of the array: 91 Index of max value of the array: 11 Sum.af the array: 831 Min value of the array: 20 Index of min value of the array: 8 Average value of the array: 55.4 Above Average values in the array: Below Average values in the array

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

1, Discuss why you should study marketing.

Answered: 1 week ago

Question

What event led the United States to enter world war II?

Answered: 1 week ago

Question

The slogan 'no representation no tax' Is the result of which event?

Answered: 1 week ago

Question

Who was the first European to land in the U.S. ?

Answered: 1 week ago

Question

What year was the James town settlement established ?

Answered: 1 week ago