Suzi coded a method to delete a target element (without returning it) as follows. What is wrong with this code? Hint: There is more than one issue.

```
1 void delete( Object[] array, int numElements, Object target ){
2 int i;
3 for ( i == 0; i <= numElements; i++ )
4 if ( array[i].equals( target ) )
5 break;
6 for ( ; i <= numElements; i++ )
7 array[i] = array[i+1];
8 }

```


Line# 3: i == 0
Supposed to be assignment (=)not check for equality (==)
Line# 3: i <= numElements
Loop will be off by one; should be i < numElements
Line# 5: break;
Not an error, but potentially confusing. The break will cause the for loop on line 3 to exit, which is what we need.
Line# 6: i <= numElements; should be i < ( numElements – 1 )

Lastly, numElements needs to be decremented only if target was found and deleted.

Computer Science & Information Technology

You might also like to view...

How does the use of a networking switch minimize problems with packet sniffing in a LAN?

What will be an ideal response?

Computer Science & Information Technology

A DHCP __________________ is a range of IP addresses that a DHCP server can give out to requesting clients.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

When an array is created, the compiler automatically creates an internal ____ for it and stores the base address of the array in it.

A. pointer constant B. pointer C. symbolic constant D. location

Computer Science & Information Technology

____ can allow a browser to display additional content it was not originally designed to display.

A. Plug-ins B. HTML5 C. Legacy tools D. Tags

Computer Science & Information Technology