• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assertions Doubt?

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Why the answer for the following code is "The last number to be printed is 4 if assertions are enabled at run time? Wont it print 6?


}

Regards,
Jothi Shankar Kumar. S
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, running it with assertions enabled prints:
0
3
4

Why do you think it should print 6?
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Barry,

Thought foolishly and forgot that j will be incremented in the next line.
I got it. Thanks anyways.

Regards,
Jothi Shankar Kumar. S
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Making a mistake is not foolish, it is a necessary part of the learning experience. But if you do believe that a piece of code is not correct, then compile and run it first, then you at least know if the problem is with the code or with your own thinking.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic