• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Assertion Question

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

Source of the Question


Thanks and Regards,
cmbhatt
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try the code with these modifications to see what's happening at each step...
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic