Question: We are going to perform some simple operations on arrays: a) A program named Tab (class Tab.java provided herewith) contains the main method main to
We are going to perform some simple operations on arrays:
a) A program named Tab (class Tab.java provided herewith) contains the main method main to declare the following tables:
int tab1[] = { 3,55,7, 1, 88, 9, 4, -10 };
int[] tab2;
tab2 = new int[]{10,34,62,56,82,7,95};
Implement in the Tab class, a sort() method that sorts the elements of an array in ascending order (use the previous sort method). This method is called for the arrays tab1 and tab2 in the main program to sort them and display the sorted elements of the two arrays.
b) Add an average() method that calculates and displays the average value of an array. The average method has only one parameter, it is the reference of an array whose elements are of type int. The method must return the average of the values in the array. You will need to save the return value in a variable of type int. The main method (main) makes a call to the average method to find the average of the two arrays tab1 and tab2 and displays their averages.
Attached is the Tab program with the main main program for testing. You must complete the methods in the places indicated, WITHOUT modifying the main method.
Example output:
The sorted elements of tab1 are:
-10, 1, 3, 4, 7, 9, 55, 88
The sorted elements of tab2 are:
7, 10, 34, 56, 62, 82, 95
The average value of tab1 is 19
The average value of tab2 is 49
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
