1. Start checking divisors from 2 (instead of
forI - 1).
2. Check divisors up to sqrt(forI).
3. Apart from 2 don't try to divide by even number (if a number is even, it is not pime -- except for 2).
4. Check this:
Sieve of Eratosthenes
On my PC calculating using your program took 19 seconds.
After I modified it acording to points 1, 2 and 3 (I didn't even try to implement the Sieve) it took... 23 milliseconds. It was almost 1000 times faster!
Apart from that:
Those variables should be declared in
main method.
Also, consider writing isPime method. Your code would look cleaner and nicer.