aboutsummaryrefslogtreecommitdiffstats
path: root/csci1913/Java
diff options
context:
space:
mode:
authorRossTheRoss <mstrapp@protonmail.com>2019-10-13 13:46:46 -0500
committerRossTheRoss <mstrapp@protonmail.com>2019-10-13 13:46:46 -0500
commit47abbc97a47b816921ea725ad9a72240c22c41f4 (patch)
tree2bc223f6c36bb67da55e4457ab55e03286d47e40 /csci1913/Java
parentS (diff)
downloadhomework-47abbc97a47b816921ea725ad9a72240c22c41f4.tar
homework-47abbc97a47b816921ea725ad9a72240c22c41f4.tar.gz
homework-47abbc97a47b816921ea725ad9a72240c22c41f4.tar.bz2
homework-47abbc97a47b816921ea725ad9a72240c22c41f4.tar.lz
homework-47abbc97a47b816921ea725ad9a72240c22c41f4.tar.xz
homework-47abbc97a47b816921ea725ad9a72240c22c41f4.tar.zst
homework-47abbc97a47b816921ea725ad9a72240c22c41f4.zip
Finish lab (rather easy)
Diffstat (limited to 'csci1913/Java')
-rw-r--r--csci1913/Java/lab5_strap012.java33
1 files changed, 29 insertions, 4 deletions
diff --git a/csci1913/Java/lab5_strap012.java b/csci1913/Java/lab5_strap012.java
index f7f9467..45a101b 100644
--- a/csci1913/Java/lab5_strap012.java
+++ b/csci1913/Java/lab5_strap012.java
@@ -10,10 +10,35 @@
//
// Put your code for the class SIEVE here!!!
//
-class sieve {
-
- public sieve(){
- for
+class Sieve {
+ private boolean[] numbers;
+ private int realMax;
+ public Sieve(int max){
+ if (max<2)
+ throw new IllegalArgumentException();
+ numbers = new boolean[max];
+ realMax = (max - 1);
+ for (int i=2; i<max; i+=1) { numbers[i]=true; }
+ }
+ public void findPrimes() {
+ for (int i=2; i<=realMax; i+=1) {
+ //Only look for composite numbers if the number is prime
+ if (numbers[i]) {
+ for (int j=(i*2); j<=realMax; j+=i) {
+ numbers[j]=false;
+ }
+ }
+ // System.out.println(i);
+ }
+ }
+ public String toString(){
+ String str = "";
+ for (int n = 0; n <= realMax; n += 1) {
+ if (numbers[n]) {
+ str += n; str += " ";
+ }
+ }
+ return str;
}
}
// TOSS THE KNEES. Run SIEVE on some examples.