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); } }
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);
}
}
Step by step
Solved in 2 steps with 1 images