Improving the algorithm

Figure 303. Implementation observation Slide presentation Create comment in forum
101 / 2  = 50.5
101 / 3  = 33.6...
101 / 4  = 25.25
101 / 5  = 20.20
101 / 6  = 16.83...
101 / 7  = 14.43...
101 / 8  = 12.625
101 / 9  = 11.2...
101 / 10  = 10.1
101 / 11  = 9.18...
101 / 12  = 8.4...
101 / 13  = 7.7...
...

Figure 304. Changing the implementation Slide presentation Create comment in forum

Big performance gain:

public static boolean isPrime(int value) {
  for (int i = 2; i * i < value; i++) {
    if (0 == value % i) {
      return false;
    }
  }
  return value != 1;
}

Figure 305. Regression test Slide presentation Create comment in forum
Regression test

Figure 306. Systematic error debugging Slide presentation Create comment in forum

Figure 307. Error correction in detail Slide presentation Create comment in forum
public static boolean isPrime(int value) {

//for (int i = 2; i * i < value; i++) {
  for (int i = 2; i * i <= value; i++) {
    if (0 == value % i) {
      return false;
    }
  }
  return value != 1;
}