Test:Computer Science

Consider the following code:

public static int[] del(int[] a,int delIndex) {

if(delIndex < 0 || delIndex >= a.length) {

return null;

}

int[] ret = new int[a.length - 1];

for(int i = 0; i < a.length; i++) {

if(i != delIndex) {

ret[i] = a[i];

}

}

return ret;

}

1.

What is the error in the code above?

You need to implement a swap for the values.

The intial conditional (i.e. the if statement) has incorrect logic.

The loop is infinite.

There is a null pointer exception.

The use of the array indexiis incorrect.

1/3 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
  • 邀请你的朋友
  • 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 LLCTerms of UseandPrivacy Policy.
Learning Tools by Varsity Tutors