Skip to content

Instantly share code, notes, and snippets.

@jonathan-irvin
Last active August 29, 2015 14:19
Show Gist options
  • Save jonathan-irvin/22f8339849d0e5b44b6a to your computer and use it in GitHub Desktop.
Save jonathan-irvin/22f8339849d0e5b44b6a to your computer and use it in GitHub Desktop.
Bruteforce Prime finder in java
public class BrutePrime {
public static void main(String[] args) {
final int END_VALUE = 1000000;
for(int number=2;number<END_VALUE;number++){
boolean isPrime = true;
//check divisors to see isPrime
for(int divisor=2;divisor<number;divisor++){
if(number % divisor ==0){
isPrime = false;
break;
}
}
//isPrime, output
if(isPrime == true){
System.out.println(number);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment