Improving the algorithm

Figure 356. 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 357. Changing the implementation Slide presentation Create comment in forum
public static boolean isPrime(int value) {
  for (int i = 2; i * i < value; i++) {
    if (0 == value % i) {
      return false;
    }
  }
  return value != 1;
}

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

Figure 359. Correcting the implementation Slide presentation Create comment in forum
public static boolean isPrime(int value) {
  for (int i = 2; i * i <= value; i++) {
    if (0 == value % i) {
      return false;
    }
  }
  return value != 1;
}

Figure 360. Repeating regression test Slide presentation Create comment in forum
Repeating regression test