Ask Question

Make sure to read all of these specifications carefully. Write a function, named array_shifter, that accepts an array of doubles and the array's size as arguments. The function should create a new array that is one element larger than the argument array.

+3
Answers (1)
  1. 19 March, 03:44
    0
    import java. util. Arrays;

    public class num2 {

    public static void main (String[] args) {

    //Create and initialize the first array

    double [ ]arr = {3.5, 5.6, 4.5, 6.7};

    / / Get the length of the array

    int n = arr. length;

    //Call the method Array Shifter inside the output statement

    System. out. println (Arrays. toString (array_shifter (arr, n)));

    }

    static double [] array_shifter (double [ ] doubleArray, int n) {

    double [] narr = new double[n+1];

    //Loop through from index 1

    for (int i = 0; i
    narr[i] = doubleArray[i];

    }

    //Put a new element at the last index

    narr[narr. length-1] = 1.1;

    return narr;

    }

    }

    Explanation:

    This is implemented in Java

    Read detailed comments in the solution

    The method array_shifter creates a new array that is one element larger than the array it received as argument and returns it
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Make sure to read all of these specifications carefully. Write a function, named array_shifter, that accepts an array of doubles and the ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers