Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Sean Anderson   on Jul 30 In Java Category.

  
Question Answered By: Becky Baker   on Jul 30

roughly...

int range = 100;
boolean prime  = true;

for(int i=0; i!=range; i++)
{
for (int j=0; j!=i; j++)
{
if ( i mod j == 0 )
prime=false;
break;
}

if(prime)
{
// caught prime number
}

}

basically though, it is better to store found prime numbers in an
ArrayList. Then you can check  prime numbers in the array list, and
then those numbers that are larger than the largest known prime
number.

To find if a number is prime, use the inner for loop.

Share: