• Post Reply Bookmark Topic Watch Topic
  • New Topic

Flaw in 99 cups of coffee example in HFJ  RSS feed

 
Durga Kannan
Greenhorn
Posts: 22
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
I am going through the HeadFirst java.In that i saw the below code.It says it is having 1 flaw in it.But i run the code successfully.Could you please figure it out the flaw in it.Thanks.

Here comes the code:
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Durga Kannan wrote:It says it is having 1 flaw in it.But i run the code successfully.

Who is saying that there is a flaw in this code, and what exactly does that mean - do you see an error or warning message somewhere? If yes, then what is the message?
 
Durga Kannan
Greenhorn
Posts: 22
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jesper,
Many thanks for your kind reply... Oh i think i misunderstood. By the way i am not seeing either error or warnings. sorry my question again is, up to my knowledge there is no space for getting any errors/warnings. Please correct me,if my view is wrong.
Thank you so much
 
Campbell Ritchie
Marshal
Posts: 55768
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have had to divide this thread because it was unrelated to the original question.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that 'flaw' could refer to a logic error. I can write lots of code that compiles and runs, but doesn't actually do what I want it to.

Taken exactly as it's given here, there are a few issues. It prints lines like this:

8cupsof coffee on the rack


There are at least two missing spaces, and no punctuation.

 
jishnu dasgupta
Ranch Hand
Posts: 103
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no flaw as such but the statement




is redundant!!
 
Campbell Ritchie
Marshal
Posts: 55768
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That spacing error might be a copying error; it's not actually an example from HFJ but a slightly changed version of the 99 bottles of beer app on page 20. And that definitely has spaces which are here replaced by empty strings. So that isn't the flaw. I think I know what it is; you have to see the output to know.
And the redundant or unused imports don't count.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!