Create an account to track your scores
and create your own practice tests:
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? |
The use of the array index i is incorrect.
There is a null pointer exception.
The loop is infinite.
The intial conditional (i.e. the if statement) has incorrect logic.
You need to implement a swap for the values.
John
Certified Tutor
Certified Tutor
University of Advancing Technology, Bachelors, Computer Science. University of California-Riverside, Masters, Computer Science.
Computer Science Tutors in Top Cities:
Atlanta Computer Science Tutors, Austin Computer Science Tutors, Boston Computer Science Tutors, Chicago Computer Science Tutors, Dallas Fort Worth Computer Science Tutors, Denver Computer Science Tutors, Houston Computer Science Tutors, Kansas City Computer Science Tutors, Los Angeles Computer Science Tutors, Miami Computer Science Tutors, New York City Computer Science Tutors, Philadelphia Computer Science Tutors, Phoenix Computer Science Tutors, San Diego Computer Science Tutors, San Francisco-Bay Area Computer Science Tutors, Seattle Computer Science Tutors, St. Louis Computer Science Tutors, Tucson Computer Science Tutors, Washington DC Computer Science Tutors
Popular Courses & Classes
MCAT Courses & Classes in San Francisco-Bay Area, ACT Courses & Classes in Phoenix, SSAT Courses & Classes in Dallas Fort Worth, Spanish Courses & Classes in New York City, ACT Courses & Classes in Philadelphia, LSAT Courses & Classes in Seattle, MCAT Courses & Classes in New York City, Spanish Courses & Classes in Philadelphia, SSAT Courses & Classes in Chicago, SAT Courses & Classes in Dallas Fort Worth
Popular Test Prep
SAT Test Prep in Boston, SAT Test Prep in Seattle, SAT Test Prep in Phoenix, LSAT Test Prep in Philadelphia, ACT Test Prep in Seattle, ISEE Test Prep in Dallas Fort Worth, ISEE Test Prep in San Diego, ACT Test Prep in Philadelphia, SSAT Test Prep in Atlanta, SSAT Test Prep in Washington DC
