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 searches for a value in the array, storing a new value at the index at which that value was found

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

None of the others answers

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

1/2 questions

0%

Access results and powerful study features!

Take 15 seconds to create an account.
Start now! Create your free account and get access to features like:
  • Full length diagnostic tests
  • Invite your friends
  • Access hundreds of practice tests
  • Monitor your progress over time
  • Manage your tests and results
  • Monitor the progress of your class & students
By clicking Create Account you agree that you are at least 13 years old and you agree to the Varsity Tutors LLC Terms of Use and Privacy Policy.
Learning Tools by Varsity Tutors