Ans:With assertions enabled it prints 210210 followed by an AssertionError message. With assertions disabled it prints 210210-1
--really need someone to explain it to me.can't understand. and if i want to complie,what's command i need to input
How to fix the following error to make the program work? Asser.java:10: warning: as of release 1.4, assert is a keyword, and may not be used as an identifier assert j == 2; ^ Asser.java:10: ';' expected assert j == 2;
Hi Dan, If u want to use assertion u have to put javac -source 1.4 <Source File Name>.
For Execution java -ea <Class Name> or java -enableassertions <Class Name>
Syntax for Assertion is: assert <boolean expression>:expression If the boolean expression is false and the assertions enabled,expression value is passed to Assertion Error Constructor.This value is converted into string format when assertion fails.
210210 get printed for the values of i from 5 to 0 .
When i=-1 , it goes into the default case of the switch statement. and it fails at the assertion ie assert i==2 and hence it gives the assertionError (when assertion are enabled ) and thus terminates .
when we disable assertion the assert command is not executed and system print the -1 value of the i.