File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assertion Question

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Source of the Question


Thanks and Regards,
cmbhatt
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the code with these modifications to see what's happening at each step...
 
tapeshwar sharma
Ranch Hand
Posts: 245
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1710
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic