0%
0 / 2 answered
Deletions Practice Test
•2 QuestionsQuestion
1 / 2
Q1
public static boolean remove(int<u></u> arr, int val) {
boolean found = false;
int i;
for(i = 0; i < arr.length && !found; i++) {
if(arr<u>i</u> == val) {
found = true;
}
}
if(found) {
for(int j = i; j < arr.length;j++) {
arr<u>j - 1</u> = arr<u>j</u>;
}
arr<u>arr.length - 1</u> = 0;
}
return found;
}
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
public static boolean remove(int<u></u> arr, int val) {
boolean found = false;
int i;
for(i = 0; i < arr.length && !found; i++) {
if(arr<u>i</u> == val) {
found = true;
}
}
if(found) {
for(int j = i; j < arr.length;j++) {
arr<u>j - 1</u> = arr<u>j</u>;
}
arr<u>arr.length - 1</u> = 0;
}
return found;
}
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