Logic Errors

Practice Questions

Computer Science › Logic Errors

Questions
2
1

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;

}

What is the error in the code above?

2

What is wrong with this loop?

int i = 0;

int count = 20;

int\[\] arr = \[1, 3, 4, 6, 8, 768, 78, 9\]

while (i < count) {

if (i > 0) {

arr\[i\] = count;

}

if (i < 15) {

System.out.println("HEY");

}

}

Return to subject