Skip to content

Instantly share code, notes, and snippets.

@mruv
Last active October 5, 2018 06:52
Show Gist options
  • Save mruv/b7ba30d0f6a963d96cd60e13beebe4bd to your computer and use it in GitHub Desktop.
Save mruv/b7ba30d0f6a963d96cd60e13beebe4bd to your computer and use it in GitHub Desktop.
//prints all prime numbers from 1 to 100
class PrimeNumbers{
public static void main(String[] args){
for(int i = 1; i < 100; ++i){//no. to test
boolean isPrime = true;
for(int j = 1; j < 100; ++j){
if(j != 1 && j != i){//don't divide by one or itself
if(i%j != 0)//not divisible
{
isPrime = isPrime && true;
}
else
{
isPrime = isPrime && false;
}
}//end of if
}//inner for
if(isPrime)
System.out.println(i);//print
}//outer for
}//end of main
}//end of class definition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment