Answer:
soo long this one is ufff
Implement the ArrayMethod application containing an array that stores eight integers. The application should call the following five methods: 1. display - should display all the integers 2. displayReverse - should display all the integers in reverse order 3. displaySum - should display the sum of the integers 4. displayLessThan - should display all values less than a limiting argument 5. displayHigherThanAverage - should display all values that are higher than the calculated average value.
Answer:
public static void display(int [] arr){
System.out.print("Arrays: ");
for(int i =0;i<arr.length;i++){
System.out.print(arr[i]+" ");
}
System.out.println();
}
public static void displayReverse (int [] arr){
System.out.print("Arrays in reverse order: ");
for(int i=arr.length-1;i>=0;i--){
System.out.print(arr[i]+" ");
}
System.out.println();
}
public static int displaySum (int [] arr){
System.out.print("Sum: ");
int sum = 0;
for(int i =0;i<arr.length;i++){
sum+=arr[i];
}
return sum;
}
public static void displayLessThan (int [] arr, int num){
System.out.print("Less than "+num+": ");
for(int i =0;i<arr.length;i++){
if(arr[i]<num){
System.out.print(arr[i]+" ");
}
}
System.out.println();
}
public static void displayHigherThanAverage (int [] arr){
System.out.print("Higher than average: ");
int sum = 0;
for(int i =0;i<arr.length;i++){
sum+=arr[i];
}
float average = sum/arr.length;
for(int i =0;i<arr.length;i++){
if(arr[i]>average){
System.out.print(arr[i]+" ");
}
}
System.out.println();
}
Explanation:
The methods were written in Java. See attachment for explanation where I used comments to explain each lines.
Note that lines that begin with double slash (//) are comments