Q: I have a program that calculates the first 200 prime numbers, but I do not understand a formula in it I need to write a code which should calculate the first 200 prime numbers, but I can't hand it in as long as I can't explain everything. I used a piece of code from the internet as reference (http://crab.rutgers.edu/~dhong/cs325/chapter3/PrimeNumber.java). 
Whole code:
public class Opdracht3 {
    public static void main(String[] args) {
        int limiet = 200;
        int counter = 1;
        int testpriem = 3;
        boolean isPriem;

        while (counter <= limiet) {
            isPriem = true;
            for (int i = 2; i <= testpriem / 2; i++) {
                if (testpriem % i == 0) {
                    isPriem = false;
                    break;
                }
            }
            if (isPriem) {
                System.out.println(counter + ": " + testpriem);
                counter++;
            }
            testpriem++;
        }
    }
}

Below part of code verifies if the number is a composite. If testpriem is composite, then comes out of the loop and starts over. Otherwise, it continues and prints the prime number testpriem.
The problem is here:
for (int i = 2; i <= testpriem / 2; i++) {
   if (testpriem % i == 0) {
      isPriem = false;
      break;
   }
}

I tested what happens to i, and one way or another it recognizes the divisor needed to calculate the composite. (With 4 divisor is 2, with 9 divisor is 3, with 221 divisor is 13) But I am flabbergasted as of why. 
Any ideas?. 

A: the % or ("remainder") operator in Java divides one operand by another and returns the remainder as its result.  And of course if integer x is evenly divisible by another integer y (meaning x/y = some integer z with a remainder of zero), then x can not be prime.

A: First remember every number able to divide by its half or less. Consider number 7 it is possible divided by 1,2,3 because after 3, if try to divide number by 4 means 4x2 = 8 that is greater than 7. so it is optimum way to find divisor in this way. One more thing every number divided by 1 and number itself. so if number number is divided by 1 or itself then it is called prime so i starts from 2.
now consider testpriem =7 so you will get loop like
for (int i = 2; i <= 7 / 2(i.e 3); i++)
    {
            if(7 % i == 0)
            {
                isPriem = false; 
                break;
            }

so first time it checks 7%2=1 so condition false. again check for 7%3 = 1 again condition false. and now this condition full fills here i <= 7 / 2(i.e 3) so loop stopped and it result 7 number is prime

A: Well, if testpriem % i == 0, it means that i divides testpriem, which means that testpriem is not a prime a number and i, is its first divider. % is the modulo operation, which is the rest of the division. 
https://en.wikipedia.org/wiki/Modulo_operation

A: The break stops the for loop and moves to the next position in the while loop.  So it does not restart the for loop for the current tested number. 
The break is used for efficiency reasons. You could remove it and the algorithm would still work correctly but slower.
