import java.util.Scanner;
public class BooleanPrimes {
public static void main(String[] argh)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a number: ");
int size = scanner.nextInt();
boolean[] boolArray = new boolean[size];
generateBoolArray(boolArray,size);
}
public static boolean[] generateBoolArray(boolean[] boolArr, int size)
{
for (int i = 2; i < size; ++i)
{
boolArr[i] = true;
}
return chickIfIndexisPrime(boolArr, boolArr.length,size);
}
public static boolean[] chickIfIndexisPrime(boolean[] arrIsPrime, int input,int size)
{
int start = 2;
while (start <= input)
{
int i = 2;
boolean isprime = true;
while(i < start )
{
if(start%i == 0) {
isprime = false;
}
++i;
}
if(isprime==true){
for(int j=4; j<arrIsPrime.length ;++j)
{
if(j%start ==0)
{ j=j==start?++j:j;
arrIsPrime[j]=false;
}
}
}
++start;
}
printArray(arrIsPrime,size);
return arrIsPrime;
}
public static void printArray(boolean[] arr ,int size){
System.out.println("The prime numbers from 2 till "+size);
int i=0,j = 0 ;
while(i<arr.length){
if(arr[i]==true){
System.out.print(i+",");
}
++i;
}System.out.println();
while(j<arr.length){
System.out.print("{Index: "+j+" "+arr[j]+"} ");
++j;
}
}
}