Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public classJan19b { public static booleanisPrime(int n) { int root = (int)Math.

ID: 3616505 • Letter: P

Question

public classJan19b
{

    public static booleanisPrime(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(Stringargs[])
    {
        int c=0;
        long start, end,mstime;

        finalint 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);
    }
}

Explanation / Answer

please rate - thanks I assume you mean the Sieve ofEratosthenes import java.io.*; public class sieveofE {public static void main(String[] args) {int i,j,max=1000000; boolean sieve[]=new boolean[max]; for(i=0;i