Question text in black, answers in blue.
Please note several corrections of L&C's questions on the assignment page.
That's a good idea for a save, but it's pretty
clear from their code that they want the lowest number first. What
you should do here is say when the exception will occur, but continue
as
though every line with a remove
call is in a block like:
so that the
try{
X.remove(...);}
catch (ElementNotFoundException e) { }
remove
acts more like a poll
.
String
as input and return true
if it is a
valid
identifier?
No, that would be a sensible thing to ask, but
it is not what I am asking. The model here is the recursive
definition of a list on page 186 of L&C -- a list is a number (the
base case) or a list, followed by a comma and a number (the
recursive case). A String
in Java is either the empty
string ""
(the base case), or a String
followed by a character. You should be able to give a similar
definition for identifiers.
find
method in the array implementation of a list? I would like to find
the first null spot in the array and return the index.
Let's see what the method on page
156 will do if you call it with parameter null
. The
first time you check an element, it says
target.equals(list[scan])
, and this will throw a
NullPointerException
if target
is null.
They could have said list[scan].equals(target)
instead,
but this would have thrown an exception whenever the scan reached a
null
entry of the list. Of course, you could write your own separate
findNull
method that would do this specific job.
Last modified 7 November 2011