Since operands of operators are evaluated from left to right, the integer cast is occurring first in this statement
mines = (int) Math.random()*100;
causing the first term to be cast to 0
. This causes counter
to be decremented as soon as it is incremented resulting in the loop repeating itself ad infinitum. Enclose the operands in parenthesis:
mines = (int) (Math.random() * 100);