aspose file tools
The moose likes Beginning Java and the fly likes Head First Java SimpleDotCom program help please... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Head First Java SimpleDotCom program help please..." Watch "Head First Java SimpleDotCom program help please..." New topic
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
    
  15

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
    
  15

I would suggest you to read this section from the Java tutorials which cautions the programmers to such kind of errors.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Java SimpleDotCom program help please...
 
Similar Threads
Hi All, While working with Head first java, I got into a problem, please help me to solve this.....
return values in methods
HFJ 2nd - Problem with SimpleDotCom
getting exception in thread "main" java.lang.NoSuchMethodError: main error message
This code of mine is not working, Please help.... i am studying from Head first java