Will some one please modify this code so that it creates an arrayand stores all
ID: 3616282 • Letter: W
Question
Will some one please modify this code so that it creates an arrayand stores all the prime numbers in it as it finds them. And also,instead of having (n%i==0) in the isPrime method, have n % by theprime numbers in the array that are less than the square root of n.Thanks very very very much.public class Jan19b
{
public static boolean isPrime(int n)
{
int root = (int) Math.sqrt(n);
for (int i=2; i<=root; i++) {
if ((n%i) == 0) {
return false;
}
}
return true;
}
public static void main(String args[])
{
int c=0;
long start, end, mstime;
final int LIMIT=100; // 1M took ~800 secs.
start = System.currentTimeMillis();
for (int i=2; i<LIMIT; i++) {
if (isPrime(i)) {
System.out.println(i);
c++;
}
}
end = System.currentTimeMillis();
mstime = end - start;
System.out.println("#primes = " + c + ", mstime = " + mstime);
}
}