Test: Computer Science

public static int[] doWork(int[] arr, int val,int index) {

            int[] ret = new int[arr.length + 1];

            for(int i = 0; i < index; i++) {

                        ret[i] = arr[i];

            }

            ret[index] = val;

            for(int i = index + 1; i < ret.length; i++) {

                        ret[i] = arr[i - 1];

            }

            return ret;

}

1.

What does the code above perform?

It inserts a new value in to an array, adding that value to the existing array

It inserts a new value into an array by overwriting the value that was there before

It searches for a value in the array, storing a new value at the index at which that value was found

None of the others answers

It deletes a value from the array, so long as it is at a given index

1/2 questions

0%
Learning Tools by Varsity Tutors