javascript
Brief description  about Online courses   join in Online courses
View gurdip  sahota 's Profile

how to find prime numbers in array

Hi guys
cant get my head around prime numbers. first of all I didnt understand what prime numbers are. now I know little but cant figure out how to find prime number in an array. e.q.
array is int[] s={10, 13, 15, 45, 60, 120}

be great if you would guide me in right direction
Asked by gurdip sahota | Dec 28, 2010 |  Reply now
Replies (2)
View gurdip sahota 's Profile
below is code so far... its not giving me desired output. would you pls advise me how to proceed further...
and also JT pls allow me to upload assignment again. thanks in advance

class PrimeTesting{
public static void main(String[] args){
int[] integerArray={12,34,35,42,9,76,31,54,99,150};
int testPrimeNumber=31;
int i, j;

boolean gotIt=false;
for( i=0; i<integerArray.length; i++ ){
if(integerArray[i]==testPrimeNumber){

for( j=2; j<integerArray[i]; j++ ){


if(integerArray[i]%testPrimeNumber!=0){



gotIt=true;
break;
}
}
}


if(gotIt) {
System.out.println("found the prime no. "+ testPrimeNumber+ " at index "+i );
}
else
{
System.out.println("given number is not prime number");
}
}
}
}
Dec 30, 2010
View arun kumar das 's Profile
Hi gurdip sahota

you should try your self, the prime number is divide by 1 and it self only, now you should create the logic your self. if still your are unable to do that than let me know.

java teacher

Dec 29, 2010