case 1's i= 1 case 2's i= 2 case 3's i= 3 case 4's i= 4 case 5's i= 5 case default's i= -2147483647 Exception in thread "main" java.lang.AssertionError: error Mr. Akshay Fix it!!! at scjp.Code.TechnoSample.main(A.java:16)
Well i can figure out till "case 5" but then why Integer.MIN_VALUE appears at default case together with AssertionError.
It this something to do with infinite for loop???I can't figure out.
According to my understanding ,when the application prints the value of i as 5, the control goes out of switch statement and passes to boolean expression of while loop where the expressionis true and value of i is now 6.then it should execute default statement and should print case default's i=6 toghter with AssertionError.
After "case 5's i=5" prints, control returns to the for loop since i>=5. Every time the condition in the while loop is checked, i gets incremented by 1. Finally, when i==Integer.MAX_VALUE get incremented, i==Integer.MIN_VALUE. Since this value is negative, i<5. Which means you enter the while loop, go to the default condition and throw an exception. [ December 17, 2005: Message edited by: Philippe Saint-Just ]