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

I keep on getting this error for some reason and dont really see what i have wro

ID: 3528784 • Letter: I

Question


I keep on getting this error for some reason and dont really see what i have wrong here. here is the original question for this problem.


1. The Sieve of Eratosthenes is a method of finding all prime numbers up to some fixed upper limit. It operates in the following way:

(a). Create an array of boolean values all initialized to true. As the algorithm progresses, array elements with prime subscripts will remain true, while all other array locations will end up with false values.

(b) Starting with array location 2, if a particular location contains true, then loop through the remainder of the array and set to false each location whose subscript is a multiple of the element which is true. So, since location 2 is true, you loop through all multiples of 2, setting those locations to false. Next, since location 3 is also still true, loop through the rest of the array marking every position that is a multiple of 3 to false. Continue this process until you have reached the square root of the array size.

Use the Sieve of Eratosthenes to determine how many prime numbers there are that are less than one million.

Anyone who can help will get 5 stars for review. Thanks in advance!!!


Explanation / Answer

public class SieveOfEratosthenes {

public static void main(String[] args) {

boolean[] array = new boolean[100];

for (int i = 0; i < array.length; i++) {

array[i] = true;

}

for (int i = 2; i <= Math.sqrt(array.length); i++) {

if (array[i] == true) {

for (int j = i + 1; j < array.length; j++) {

if (j % i == 0) {

array[j] = false;

}

}

}

}

System.out.println("List Of prime number upto " + array.length + " : ");

for (int i = 2; i < array.length; i++) {

if (array[i] == true) {

System.out.print(i + " ");

}

}

}

}

Output

List Of prime number upto 100 :