write a Java method merge that takes as parameter a non-empty double array representing employees’ salaries. The method merges the values of every 2 adjacent elements. put the merged values at the beginning of the array, and put 0 in the remaining positions. Suppose that the original array will contain an even number of elements. Second, write two java methods readArray(int[]a) and printArray(int[]a) that reads/writes the elements of an array passed in parameter from/to the standard input/output.
First, write a Java method merge that takes as parameter a non-empty double array representing employees’ salaries. The method merges the values of every 2 adjacent elements. put the merged values at the beginning of the array, and put 0 in the remaining positions. Suppose that the original array will contain an even number of elements.
Second, write two java methods readArray(int[]a) and printArray(int[]a) that reads/writes the elements of an array passed in parameter from/to the standard input/output.
Finally, Use the following main method to test your different methods:
public class MergeSalary {private static Scanner input = new Scanner(System.in);
public static void main(String[] args) {} }
double[] salaries = new double[10]; System.out.print("Enter 10 salaries: "); readArray(salaries);
merge(salaries);System.out.print("Salaries after merge: "); printArray(salaries);
Hint: For the method merge, you can work on the same array or use a temporary array.
Run example:
Enter 10 salaries:
1000 1000 2000 2000 3000 3000 4000 4000 5000 5000
Salaries after merge:
2000.00 4000.00 6000.00 8000.00 10000.00 0.00 0.00 0.00 0.00 0.00
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images