Question: import java.util.Scanner; public class SieveOfEratosthenes { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println(Enter a number); int num = sc.nextInt(); boolean[]
import java.util.Scanner;
public class SieveOfEratosthenes { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a number"); int num = sc.nextInt(); boolean[] bool = new boolean[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 Can you comment the code along with adding improvements to it. I also need it to print out it's execution and run time. The language is in java. Make sure it prints out the run time after the execution and printing of the prime numbers. This program is the Sieve of Eratosthenes that calculates the prime numbers leading up to a number.http://www.algolist.net/Algorithms/Number_theoretic/Sieve_of_Eratosthenes
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
