• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question on assertion

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

With assertions enabled the above code prints
210210Exception in thread "main" java.lang.AssertionError
at asert2.m1(asert2.java:12)
at asert2.main(asert2.java:19)
My doubt is shouldn't it print 210210-1 followed by assertion error?
Thanks
Veena
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Veena Point:

With assertions enabled the above code prints
210210Exception in thread "main" java.lang.AssertionError
at asert2.m1(asert2.java:12)
at asert2.main(asert2.java:19)
My doubt is shouldn't it print 210210-1 followed by assertion error?
Thanks
Veena


I think the answer is correct. Since when Assert is false, the EXIT method will be called. So the -1 won't be printed. Am I right?
Shirley
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even I thought like that.But then again if that is the case why is it printing 01 in between....?
Thanks
Veena
 
shirley tao
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Veena Point:
Even I thought like that.But then again if that is the case why is it printing 01 in between....?
Thanks
Veena


You mean the 0 1 in the printing string. I think that's because it is in the switch block, when j=0 or j=1, it goes to the case "0" or "1" and doesn't execute the sentences in the case default, so assert won't be executed. Am I right?
Shirley
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh,I misunderstood the assert statement actually.sorry.Yeah you are right .But your explanation helped alot.
Thank you very .
 
Look ma! I'm selling my stuff!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic