# Prime Directive

hi guys iam having a bit trouble i dont know what to do, i just started this as an experiment AND i have completed it in other way but if you can, can u please show me a way for this…This is my code

``````import java.util.ArrayList;
class PrimeDirective {

/* public boolean isPrime(int num){
if(num == 2){
}
else if (num < 2){
System.out.println("not a prime");
}
else
{
for (int i=2;i<num;i++){
if(num % i ==0)
return false;
}
}
return true;

}*/

//problems begins here...

public ArrayList<Integer> onlyPrimes(int []numbers){

ArrayList<Integer>  primes= new ArrayList<Integer>();

for (int number : numbers){

System.out.println(number);

if(number == 2){
}
else if (number < 2){
System.out.println("not a prime");
}
else
{
for ( int i=2;i<number;i++){

if(number % i==0){
flag++;
System.out.println("flag"+flag);
break;
}

}
}
if(flag==0)
continue;
}
return primes;
}

public static void main(String[] args) {

PrimeDirective pd = new PrimeDirective();
int[] numbers = {6, 29, 28, 33, 11, 100, 101, 43, 89};
//  System.out.println(pd.isPrime(4));
System.out.println(pd.onlyPrimes(numbers));

}

}
``````

Hi!

Thanks for sharing! Could you edit your post so that it’s formatted (hit the </> before pasting the code).

It’ll make it easier for people to see what you wrote and help out.

I’ve done that for you.