aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Labeled while loop problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Labeled while loop problem" Watch "Labeled while loop problem" New topic
Author

Labeled while loop problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

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 ?


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Saruwatari Tadayoshi
Greenhorn

Joined: Jun 22, 2010
Posts: 6
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

Joined: Sep 12, 2009
Posts: 316
Yess I think , both the solutions are valid.

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

Thanks !!!

SCJP 6.0 96%

(Connecting the Dots ....)
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

IsquishWorms Isquish Worms please check your private messages for some administrative matter...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Saruwatari Tadayoshi
Greenhorn

Joined: Jun 22, 2010
Posts: 6
Done sorry about that I should of read the rules.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Labeled while loop problem
 
Similar Threads
Puzzling question
exercise: creating a Labeled while Loop: anyone can help me to check?
k & b exercise 5-2, why endless loop
Infinite loop
sample on illegal use of labeled continue and break