• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Labeled while loop problem

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SCJP1.6 JAVA 6 CERTIFICATION Guide-310-065
by Katherine Sierra (Author), Bert Bates (Author)
pg-356
ex-5-2


Creating a Labeled while Loop
Try creating a labeled while loop. Make the label outer and provide a condition to
check whether a variable age is less than or equal to 21. Within the loop, increment
age by one. Every time the program goes through the loop, check whether age is 16.
If it is, print the message "get your driver's license" and continue to the outer loop. If
not, print "Another year."
-- The outer label should appear just before the while loop begins.
-- Make sure age is declared outside of the while loop.





Is the solution correct ?
 
Saruwatari Tadayoshi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have also just recently completed this exercise and your answer is similar to mine. So I am guessing we are either both correct or both wrong.

Here is my code:

 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yess I think , both the solutions are valid.

You can remove "outer" from continue outer; also.

Thanks !!!
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IsquishWorms Isquish Worms please check your private messages for some administrative matter...
 
Saruwatari Tadayoshi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Done sorry about that I should of read the rules.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic