• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HeadFirst ( Page 25) exercise question. Confusion.. can somebody help

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I am a new bee in java and started to red the HeadFirst java book. On page 25, there is question on right upper side of the book class Exercose1b . the answer is "This will compile with no output bt without a line added to the program, it would run forever". Now when i first look at the code. it should type 7 times Bigx.

I am confused. Is this a typing error in the book or i cannot understand

kindly make me correct

regards
Imran
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're playing kind of Jeopardy (or what was the name of that quiz show, where answers were given and the question was to be found?).

What is the question?
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you take a look at the exercise they added x = x + 1 to the while clause. This will increment the value of x in each iteration of the loop. If you never use that statement, x would always be 1, the while statement condition (while x < 10) would never become false (x = 11), the println would never print a value because x would never be greater than 3 and it would run forever.
 
reply
    Bookmark Topic Watch Topic
  • New Topic