From c009693a07276f8d66cd68637431f0a3f0e9ef15 Mon Sep 17 00:00:00 2001 From: Julian T Date: Tue, 8 Sep 2020 13:43:21 +0200 Subject: Added more java assignments --- sem5/oop/m2/Opg1/.classpath | 10 ++++++++++ sem5/oop/m2/Opg1/.gitignore | 1 + sem5/oop/m2/Opg1/.project | 17 +++++++++++++++++ sem5/oop/m2/Opg1/hej.txt | 10 ++++++++++ sem5/oop/m2/Opg1/src/Main.java | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 sem5/oop/m2/Opg1/.classpath create mode 100644 sem5/oop/m2/Opg1/.gitignore create mode 100644 sem5/oop/m2/Opg1/.project create mode 100644 sem5/oop/m2/Opg1/hej.txt create mode 100644 sem5/oop/m2/Opg1/src/Main.java (limited to 'sem5/oop/m2/Opg1') diff --git a/sem5/oop/m2/Opg1/.classpath b/sem5/oop/m2/Opg1/.classpath new file mode 100644 index 0000000..adeb0a3 --- /dev/null +++ b/sem5/oop/m2/Opg1/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/sem5/oop/m2/Opg1/.gitignore b/sem5/oop/m2/Opg1/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/sem5/oop/m2/Opg1/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/sem5/oop/m2/Opg1/.project b/sem5/oop/m2/Opg1/.project new file mode 100644 index 0000000..1b0d3fd --- /dev/null +++ b/sem5/oop/m2/Opg1/.project @@ -0,0 +1,17 @@ + + + Opg1 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/sem5/oop/m2/Opg1/hej.txt b/sem5/oop/m2/Opg1/hej.txt new file mode 100644 index 0000000..d8c6033 --- /dev/null +++ b/sem5/oop/m2/Opg1/hej.txt @@ -0,0 +1,10 @@ +1 2 3 4 5 6 7 8 9 10 +11 12 13 14 15 16 17 18 19 20 +21 22 23 24 25 26 27 28 29 30 +31 32 33 34 35 36 37 38 39 40 +41 42 43 44 45 46 47 48 49 50 +51 52 53 54 55 56 57 58 59 60 +61 62 63 64 65 66 67 68 69 70 +71 72 73 74 75 76 77 78 79 80 +81 82 83 84 85 86 87 88 89 90 +91 92 93 94 95 96 97 98 99 100 diff --git a/sem5/oop/m2/Opg1/src/Main.java b/sem5/oop/m2/Opg1/src/Main.java new file mode 100644 index 0000000..179e678 --- /dev/null +++ b/sem5/oop/m2/Opg1/src/Main.java @@ -0,0 +1,38 @@ +import java.io.FileWriter; +import java.io.IOException; + +public class Main { + + static void writeLines(String name) throws IOException{ + FileWriter f = null; + try { + f = new FileWriter(name); + + for (int i = 1; i <= 100; i++) { + f.write(String.format("%-3d ", i)); + if (i % 10 == 0) { + f.write(System.lineSeparator()); + } + } + } finally { + if (f != null) { + f.close(); + } + } + } + + public static void main(String[] args) { + String name = "hej.txt"; + if (args.length > 0) { + name = args[0]; + } + + System.out.printf("Writing to %s%n", name); + try { + writeLines(name); + } catch(IOException e) { + System.err.printf("Failed with: %s%n", e); + } + } + +} -- cgit v1.2.3