This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertions Doubt? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assertions Doubt?" Watch "Assertions Doubt?" New topic
Author

Assertions Doubt?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9353
    
    2

Hi Guys,

Why the answer for the following code is "The last number to be printed is 4 if assertions are enabled at run time? Wont it print 6?


}

Regards,
Jothi Shankar Kumar. S


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Well, running it with assertions enabled prints:
0
3
4

Why do you think it should print 6?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9353
    
    2

Hi Barry,

Thought foolishly and forgot that j will be incremented in the next line.
I got it. Thanks anyways.

Regards,
Jothi Shankar Kumar. S
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Making a mistake is not foolish, it is a necessary part of the learning experience. But if you do believe that a piece of code is not correct, then compile and run it first, then you at least know if the problem is with the code or with your own thinking.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Assertions Doubt?