File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertion Question 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 "Assertion Question" Watch "Assertion Question" New topic
Author

Assertion Question

Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707

:roll:
Please describe the output in case assertion enabled and disabled.

Source of the Question


Thanks and Regards,
cmbhatt


cmbhatt
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Try the code with these modifications to see what's happening at each step...


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
tapeshwar sharma
Ranch Hand

Joined: Mar 10, 2006
Posts: 245
first 210210 is printed out, then at the last iteration (i.e for -1),the assertion will fail and the system will throw an AssertionError in case assertion is enabled.
Otherwise, it will simply output -1, so output will be 210210-1.
Am i wrong in trying to answer this question or what?
Sorry,i don't frequent this site too much so may be I am unaware of the protocol.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by prashant bhardwaj:
... Am i wrong in trying to answer this question or what? Sorry,i don't frequent this site too much so may be I am unaware of the protocol.

No, not wrong at all. It's just that sometimes the best way to help someone learn is to give them tips on how to figure out the solution themselves, instead of providing an answer. As they work through it, they may learn other things. And when they do arrive at a solution, it will probably be easier to remember because they worked through the process.

In this case, it's hard to tell, because Chandra's question isn't very specific. The code is complete, so it can easily be compiled to see the output. Is it really the assertion that's raising doubt? Is it the % operator? Is it the default in the switch/case? Is it the for loop?

I almost posted a line-by-line explanation of what the values were. But I decided that it might be more helpful to demonstrate how to modify the code to output these values, because this is a general technique that can be applied to a variety of problems. If that doesn't clear things up, I'm hoping Chandra will post a more specific follow-up.

Anyway, that was my reasoning.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Thanks marc,

There were so many things my sleepy brain was missing including
%, break etc. Now I feel completely comfortable with output and
the reason behind that. Yeah your trick to make somebody
understand is very nice and it helped me a lot. It helps one to
think himself instead of relying on output only.



Thank you very much marc,
cmbhatt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assertion Question
 
Similar Threads
Question on assertion
Error in code when using assertion
Assertion querry
Assertion
assert