Last active
October 18, 2022 13:53
-
-
Save KnightsWhoSayNi0/2d08c690c58c0deda6d0f881fc36899e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PrimeyTimey | |
{ | |
/* John Godman - Program 2 | |
* Strazza Pd. 8 | |
*/ | |
// configuration constants | |
public static final int START = 2, | |
END = 250; | |
public static void main(String args[]) | |
{ boolean newLine = false; | |
for (int x = START; x <= END; x++) | |
{ if (x % 10 == 0 && newLine) // format w \r if iterator passes multiple of 10 | |
{ System.out.println(); | |
newLine = false; | |
} | |
if (isPrime(x)) // iterator is prime? w/ func @ ln 20 | |
{ System.out.printf("%-4d", x); // format left aligned 4 chars | |
newLine = true; | |
} | |
} | |
} | |
// prime number function | |
public static boolean isPrime(int x) | |
{ for (int y = START; y < x; y++) | |
{ if (x % y == 0) // value divisible by iterator? | |
return false; | |
} | |
return true; | |
} | |
} | |
/* | |
int[] primesOut = new int[END - START]; | |
int arrayInc = 0; | |
for (int x = 1; x <= END; x++) | |
{ | |
for (int y = START; y < x; y++) | |
{ | |
if (x % y == 0) | |
{ | |
//arrayInc++; | |
break; | |
} | |
//primesOut[arrayInc++] = x; | |
} | |
} | |
int j = 0; | |
for (int out : primesOut) | |
{ | |
System.out.printf("%4s", out); | |
if (j++ % 10 == 0) | |
{ | |
System.out.println(); | |
j = 0; | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment