I didnt want to pen new topic so I was hoping if you can help me here I have been going though book and the exercises they have, where I came accross a problem with boolean. Code in the book is written exactly like this:
however the true/fals result can not be printed due to the "answer" variable...Is it me or the book wrong?
You ought to have started a new thread. That is a completely new question. Fortunately I can create a new thread.
You ought also to have given more details of what happens. What you wrote suggested you were not getting the answer printed, whereas I got a compile time error when I tried your code. You have not declared the variable answer anywhere. It would have worked if you had declared answer.
There are a few minor formatting errors in your code, but one serious logic error. You are closing a Scanner pointing to System.in. Other people have made the same mistake and had problems, for example in this thread.