Test: Computer Science

public static boolean remove(int[] arr, int val) {

       boolean found = false;

       int i;

       for(i = 0; i < arr.length && !found; i++) {

              if(arr[i] == val) {

                     found = true;

              }

       }

       if(found) {

              for(int j = i; j < arr.length;j++) {

                     arr[j - 1] = arr[j];

              }

              arr[arr.length - 1] = 0;

       }

       return found;

}

1.

For the code above, what will be the content of the variable arr at the end of execution, if the method is called with the following values for its parameters:

arr = {3,4,4,5,17,4,3,1}

val = 4

{3, 5, 17, 3, 1, 0, 0, 0}

None of the other answers

{3, 5, 17, 3, 1}

{3, 4, 5, 17, 4, 3, 1}

{3, 4, 5, 17, 4, 3, 1, 0}

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