To create an overflow condition, you really need to call something overflow. Like a variable.
Modify your for statement to increase something, but do not put any restrictions on the continuity of the loop, then there will be an integer overflow.
for (int i=0;;i++) { }
As an alternative,
for (int i=0;i==i;i++) { // i==i is always true. }
Another way is to cause the call stack to overflow, recursively calling itself unlimited. Each recursive call must keep a stack of the previous recursive call.
Recursive function :
public static my(){ my(); }
Recursive constructor :
class My { My my; My() { try{ my = new My(); } catch (Exception e){
source share