aboutsummaryrefslogtreecommitdiff
path: root/sem5/oop/m2/primes/src/Main.java
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-09-08 13:43:21 +0200
committerJulian T <julian@jtle.dk>2020-09-08 13:43:21 +0200
commitc009693a07276f8d66cd68637431f0a3f0e9ef15 (patch)
treefc9bc85620813e7a179b043203d25879932267f6 /sem5/oop/m2/primes/src/Main.java
parentba5f68924664b081aab1abb62c68e2fb70bdff0b (diff)
Added more java assignments
Diffstat (limited to 'sem5/oop/m2/primes/src/Main.java')
-rw-r--r--sem5/oop/m2/primes/src/Main.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/sem5/oop/m2/primes/src/Main.java b/sem5/oop/m2/primes/src/Main.java
new file mode 100644
index 0000000..e191835
--- /dev/null
+++ b/sem5/oop/m2/primes/src/Main.java
@@ -0,0 +1,32 @@
+
+public class Main {
+
+ public static void main(String[] args) {
+ System.out.println("Lets find some primes!!");
+
+ int runto = 10000;
+ if (args.length > 0) {
+ runto = Integer.parseInt(args[0]);
+ }
+
+ // Calculate length of runto as string
+ int numlen = String.valueOf(runto).length();
+
+ PrimeGen pg = new PrimeGen();
+
+ int p;
+ int index = 1;
+ while ((p = pg.next(runto)) != -1) {
+ // Terrible two level format
+ System.out.printf(String.format("%%-%dd ", numlen), p);
+ if (index % 10 == 0) {
+ System.out.print(System.lineSeparator());
+ }
+ index++;
+ }
+ System.out.print(System.lineSeparator());
+ System.out.printf("Found %d primes%n", index-1);
+
+ }
+
+}