jQuery in Action, 2nd edition*
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 Android Security Essentials Live Lessons this week in the Android 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: 9345
    
    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: 9345
    
    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?
 
Similar Threads
Multi dimensional array
assertions doubt
loop
Assertion querry
Doubt in Assertion