Answer:
See explaination for Program source code.
Step-by-step explanation:
Program source code below.
/Import the required package.
import java.util.Scanner;
//Define the class AboveAverageArray.
public class AboveAverageArray
{
//Start the execution of the main() method.
public static void main(String[] args)
{
//Create an object of scanner class.
Scanner sc = new Scanner(System.in);
//Declare and create an array of 100 integers.
int[] arr = new int[100];
//Call the method readIntoArray() and store the
//returned value into the variable countOfInt.
int countOfInt = readIntoArray(arr, sc);
//Call the method printAboveAverag() to print the
//values of the array above average value.
printAboveAverage(arr, countOfInt);
}
//Define the method printAboveAverage().
public static void printAboveAverage(int[] array, int
countOfArr)
{
//Declare the required variables.
double sumOfValues = 0;
//Calculate the sum of elements of the array.
for (int i = 0; i < countOfArr; i++)
sumOfValues += array[i];
//Calculate the average of the elements of the
//array.
double avgOfArr = sumOfValues/countOfArr;
//Display the elements which are above the
//average.
System.out.print("The elements above ");
System.out.println("average "+avgOfArr +
" are:");
for (int i = 0; i < countOfArr; i++)
{
//Check if the current element is greater than
//average or not.
if(array[i] > avgOfArr)
//Display the element with the current
//index.
System.out.println("Array["+i+"]"+" = " +
array[i]);
}
}
//Define the method readIntoArray().
public static int readIntoArray(int[] arrOfInt,
Scanner sc)
{
//Declare teh required variables.
int num_values = 0;
//Prompt the user to enter the values of the
//array till the user press CTRL+D.
System.out.print("Enter the elements of ");
System.out.println("the array: ");
//Start the try/catch block.
try
{
//Start the while loop till the scanner has
//a integer input and the number of elements
//in the array is less than 100.
while(sc.hasNextInt() || num_values <
arrOfInt.length)
{
arrOfInt[num_values] = sc.nextInt();
num_values++;
}
}
//Catch block.
catch (Exception e)
{}
//Return the number of elements in the array.
return num_values;
}
}