| Author |
Head First Java SimpleDotCom program help please...
|
James Conroy
Greenhorn
Joined: Feb 11, 2012
Posts: 1
|
|
Hi,
I am having a problem with the SimpleDotCom program in the Head First Java book (chapter 5). I have completed chapter 5 and my program (basic version) works correctly except for one bug. Here's my source code:
When I run the program, it tells me how many guesses I've taken after every data input instead of at the end when isAlive is false and the ship is killed. Let me show you an example:
What am I doing wrong?
Many thanks in advance,
James.
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2925
|
|
Hi James, Welcome to JavaRanch,
There's subtle error in the code. If you dont specify the {} with the if-else statement then the compiler considers the immediate next statement as part of the if statement and statements following the immediate statement are not considered as part of the if-statement. If you have multiple statements in the if-else block, put them in the {}. But generally its more readable to separate such if-else constructs using the {}
|
Mohamed Sanaulla | My Blog
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2925
|
|
|
I would suggest you to read this section from the Java tutorials which cautions the programmers to such kind of errors.
|
 |
 |
|
|
subject: Head First Java SimpleDotCom program help please...
|
|
|