Menu

(Solved) : Import Javautilscanner Public Class Sieveoferatosthenes Public Static Void Main String Arg Q43978140 . . .

import java.util.Scanner;

public class SieveOfEratosthenes {
   public static void main(String args[]) {
      Scanner sc = newScanner(System.in);
      System.out.println(“Enter anumber”);
      int num = sc.nextInt();
      boolean[] bool = newboolean[num];
    
      for (int i = 0; i< bool.length;i++) {
         bool[i] =true;
      }
      for (int i = 2; i<Math.sqrt(num); i++) {
         if(bool[i] ==true) {
           for(int j = (i*i); j<num; j = j+i) {
              bool[j] = false;
           }
         }
      }
      System.out.println(“List of primenumbers upto given number are : “);
      for (int i = 2; i< bool.length;i++) {
         if(bool[i]==true){
           System.out.println(i);
         }
      }
   }
}

Can you comment the code along with adding improvements to it. Ialso need it to print out it’s execution and run time. The languageis in java. Make sure it prints out the run time

after the execution and printing of the prime numbers. Thisprogram is the Sieve of Eratosthenes that calculates the primenumbers leading up to anumber.http://www.algolist.net/Algorithms/Number_theoretic/Sieve_of_Eratosthenes

Expert Answer


Answer to import java.util.Scanner; public class SieveOfEratosthenes { public static void main(String args[]) { Scanner sc = new S…

OR