Answer:
import java.util.Arrays;
import java.util.Scanner;
public class num4 {
static int[] readInttoArray() {
Scanner in = new Scanner(System.in);
int [] intArray = new int [10];
System.out.println("Enter Array values");
intArray[0]= in.nextInt();
for(int i = 1; i < intArray.length; i++){
System.out.println("enter the next value ");
intArray[i] = in.nextInt();
}
return intArray;
}
static void printAboveAverage(int [] intArray){
System.out.println("The array entered is:"+ Arrays.toString(intArray));
int sum =0;
for(int i =0; i<intArray.length; i++){
sum = sum +intArray[i];
}
double ave = sum/intArray.length;
System.out.println("Average "+ave);
for(int i = 0; i<intArray.length; i++){
if(intArray[i]>ave){
System.out.println(intArray[i]+" Is above average");
}
}
}
public static void main(String[] args) {
readInttoArray();
printAboveAverage(readInttoArray());
}
}
Step-by-step explanation:
- Using Java Programming Language
- The Three Methods are Created
- readIntoArray() Uses Java's Scanner Class to prompt user to enter values to an array that is created with a for loop
- The values entered are stored in the array array and returned whenever the method is called
- printAboveAverage() Accepts an array as a parameter when called
- Calculate the sum and average values in the array using a for loop
- Uses an if statement to check for elements greater than the averaage and prints them out.
- In the Main Method, Both methods readIntoArray() and printAboveAverage() are called.