This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question about assert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question about assert" Watch "Question about assert" New topic

Question about assert

Kamil Wojcik
Ranch Hand

Joined: May 19, 2008
Posts: 78


Is this explanation to the question is really true?

SCJP 6.0 Passed | SCWCD Passed | PSM in progress...
Jehaan Butt
Ranch Hand

Joined: Feb 05, 2009
Posts: 41
Explanations : When if condition returns true, the assert statement also returns true.
Hence AssertionError not generated.

This statement in itself is true. If i<j, then naturally i!=j would not give an assertion error. It is a correct, but highly cut down version of the program explanation. The program works like this:

On the first iteration of the inner loop, i=j=2, therefore, the assert statement is not reached. Second iteration, i!=j (i=2, j=3). Here, the assert is reached, and its condition is satisfied, and so on.

What the essence of the program is, is that i can have any value with respect to j. If it is equal to or greater than j, then the assert is not reached. If i is less than j, the assert is reached, but is true. Hence, if the "if" is true, the assert is true, which is what the explanation says.

Kamil Wojcik
Ranch Hand

Joined: May 19, 2008
Posts: 78

Now I see it thanks for replay Anurag!
wood burning stoves
subject: Question about assert
It's not a secret anymore!