Skip to content

Instantly share code, notes, and snippets.

@eskatos
Created November 25, 2013 21:43
Show Gist options
  • Save eskatos/7649424 to your computer and use it in GitHub Desktop.
Save eskatos/7649424 to your computer and use it in GitHub Desktop.
public class PrimeNumbersSeeker
{
private static final int ceiling = 100;
private static final int delay = 100;
public static void main( String[] args )
{
new PrimeNumbersSeeker().seek();
}
public int count = 0;
public int current = 2;
private void seek()
{
while( count < ceiling )
{
current++;
int i = 2;
boolean isPrime = true;
while( i < current / 2 && isPrime )
{
isPrime = current % i > 0;
i++;
}
if( isPrime )
{
count++;
System.out.println( "Found "+count+" prime(s): " + current );
}
try
{
Thread.sleep( delay );
}
catch( InterruptedException ex )
{
System.out.println( "Sleep interrupted." );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment