Skip to content

Instantly share code, notes, and snippets.

@tim-peters
Forked from imsoftware/primenumbers008.java
Last active December 26, 2015 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tim-peters/7069541 to your computer and use it in GitHub Desktop.
Save tim-peters/7069541 to your computer and use it in GitHub Desktop.
// List prime numbers with processing 2
// Simplified
// By: TiPE
int[] zahlen = new int[101]; // create an array width 101 "parts" called zahlen
int anzahl = 0; // create an int for counting the primes
for(int x=1;x<=100;x++) // count from 1 to 100...
{
zahlen[x] = x; // write each number (x) in the array
for(int y=2;y<x;y++) // for each number, from 2 to the actual number (x)...
{
if((x % y) == 0) // check wether x is divisible by the number (y) without getting modulo -> the result is a "whole" number (integer)
zahlen[x] = 0; // if true: set zahlen[x] to 0 -> x is not a prime
}
}
for(int x=1;x<=100;x++) // for each number from 1 to 100
{
if(zahlen[x] != 0) // if it's part of the zahlen array is not set to 0
{
println(x); // print it's number
anzahl++; // ans add one to the anzahl int
}
}
print("\nDies sind alle "+anzahl+" Primzahlen von 0 bis 100");
@imsoftware
Copy link

1 is no prime. Use instead:

for(int x=2;x<=100;x++) // count from 2 to 100...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment