Can someone help me figure out the error in this problem of finding the gap of 100 consecutive composite number between 2 primes
The code is in java .Help find out the error import java.util.List; import java.util.ArrayList; public class Prime100 { private List<Long> primes = new ArrayList<>(); private long targetGap; public Prime100(long targetGap) { this.targetGap = targetGap; primes.add(2L); primes.add(3L); } boolean isPrime(long n) { boolean ok = true; for(long p: primes) { if(p * p > n) { break; } if(n % p == 0) { ok = false; break; } } if(ok) { long lastPrime = primes.get(primes.size() - 1); long gap = n - lastPrime; if(gap == targetGap) { System.out.println(lastPrime + " -> " + n + ": gap = " + gap); } primes.add(n); } return ok; } public static void main(String[] args) { Prime100 primeChecker = new Prime100(102); long n = 5; while(true) { primeChecker.isPrime(n++); } } }