| 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
|
 |
 |
|
|
subject: Assertion Question
|
|
|