I'm trying to change certain index values of this boolean array to false and it does change but when re-displayed in another method it doesn't print properly.
This is for an assignment at school. I've check memory locations and they are the same.
import java.util.Scanner;
import java.util.Arrays;
public class Lab11avst
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
final int MAX = 100;
boolean primes[];
primes = new boolean[MAX];
computePrimes(primes);
displayPrimes(primes);
}
public static void computePrimes(boolean list[])
{
Arrays.fill(list, true);
for (int i = 1; i < list.length ; i++)
{
if (list[i] = true)
{
for (int j = (i+1); j < 20; j+=(i+1))
{
list[j] = false;
System.out.println( j+" "+list[j]);
}
}
}
}
public static void displayPrimes( boolean x[])
{
for(int y = 1; y< (x.length); y+=1)
{
if(x[y] =true)
{
System.out.print(y+ " ");
}
}
}
}