Please help me solve this with java 1-method called printArray that takes an array of double values and prints the array elements on the same line with one space between each two elements, then prints a new line. 2. A method called getRandomElement that takes an array of double numbers and returns a random element from the array. 3. A method called shiftArray that takes a double value and an array of double values. The method must shift the array in its place to the right, and insert the double value at index 0. Note that this method must not create a new array, it must rotate the array in its place. For example, if the passed array is 6.5, 2.1, 5.8, 1.5, 8.9 and the passed double value is 3.3, after invoking the method the array must become: 3.3, 6.5, 2.1, 5.8, 1.5 4. A method called occurrences that takes a double value and an array of doubles as parameters, and returns the number of occurrences of the double value in the array. For example, if the double number 4.1 and the array {1.5, 4.1, 1.5, 2.3, 4.1, 4.1, 5.2} are passed, the method must return the number 3. 5. A method named findElement that takes a double number and an array of double numbers as parameters and returns an array that includes the indices of all the number occurrences in the array. This method must invoke the method occurrences to get how many times the value appears in the array. For example, if the double number 4.1 and the array {1.5, 4.1, 1.5, 2.3, 4.1, 4.1, 5.2} are passed, the method must return the array {1, 4, 5}. If the passed number does not occur in the array, the method must return an array of zero elements. 6. A method called print2DArray, that takes a two-dimensional array of double values, and prints its elements as a matrix of rows and columns. 7. A method called create2DArray that takes two integers, the first represents the number of rows and the second represents the number of columns. It must return a two-dimensional array of double values with the entered number of rows and columns filled with random double values between 0 and 10. 8. In your main method: - Declare, create, and initialize the following arrays of double values with the following names: list1: 3.5 6.5 1.5 6.5 6.5 8.5 5.5 1.5 list2: an array whose size and elements values are read from the user. - Print elements of the arrays list1 and list2 by invoking the printArray method. - Print a random element from list2 by invoking getRandomElement method. - Shift the array list1 three times to the right and fill the value 2.5 in the first three indices by invoking the shiftArray method. - Print the indices of the value 6.5 in the array list1 by invoking the findElement method. - Create a two-dimensional array by invoking the create2DArray method then print it to the console by invoking the print2DArray method.
Please help me solve this with java
1-method called printArray that takes an array of double values and prints the array
elements on the same line with one space between each two elements, then prints a new
line.
2. A method called getRandomElement that takes an array of double numbers
and returns a random element from the array.
3. A method called shiftArray that takes a double value and an array of double
values. The method must shift the array in its place to the right, and insert the double
value at index 0. Note that this method must not create a new array, it must rotate the
array in its place.
For example, if the passed array is 6.5, 2.1, 5.8, 1.5, 8.9 and the passed double value is
3.3, after invoking the method the array must become:
3.3, 6.5, 2.1, 5.8, 1.5
4. A method called occurrences that takes a double value and an array of doubles
as parameters, and returns the number of occurrences of the double value in the array.
For example, if the double number 4.1 and the array {1.5, 4.1, 1.5, 2.3, 4.1, 4.1, 5.2}
are passed, the method must return the number 3.
5. A method named findElement that takes a double number and an array of
double numbers as parameters and returns an array that includes the indices of all the
number occurrences in the array.
This method must invoke the method occurrences to get how many times the value
appears in the array.
For example, if the double number 4.1 and the array {1.5, 4.1, 1.5, 2.3, 4.1, 4.1, 5.2}
are passed, the method must return the array {1, 4, 5}.
If the passed number does not occur in the array, the method must return an array of
zero elements.
6. A method called print2DArray, that takes a two-dimensional array of double
values, and prints its elements as a matrix of rows and columns.
7. A method called create2DArray that takes two integers, the first represents
the number of rows and the second represents the number of columns. It must return a
two-dimensional array of double values with the entered number of rows and columns
filled with random double values between 0 and 10.
8. In your main method:
- Declare, create, and initialize the following arrays of double values with the following
names:
list1:
3.5 6.5 1.5 6.5 6.5 8.5 5.5 1.5
list2: an array whose size and elements values are read from the user.
- Print elements of the arrays list1 and list2 by invoking the printArray method.
- Print a random element from list2 by invoking getRandomElement method.
- Shift the array list1 three times to the right and fill the value 2.5 in the first three
indices by invoking the shiftArray method.
- Print the indices of the value 6.5 in the array list1 by invoking the findElement method.
- Create a two-dimensional array by invoking the create2DArray method then print it
to the console by invoking the print2DArray method.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images