summaryrefslogtreecommitdiffstats
path: root/src/de
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2014-10-15 15:02:26 +0200
committerStefan Suhren <suhren.stefan@fh-swf.de>2014-10-15 15:16:52 +0200
commit8445b7d11b29b870815c3cef137391faac9afca5 (patch)
treefdf69e6b9bac8e47614cd99d91e13bfdced35838 /src/de
downloadJava1-8445b7d11b29b870815c3cef137391faac9afca5.tar.gz
Java1-8445b7d11b29b870815c3cef137391faac9afca5.zip
First commit of my Java1 work.
Diffstat (limited to 'src/de')
-rw-r--r--src/de/fhswf/in/inf/java1/aufgabe1/HelloWorld.java45
-rw-r--r--src/de/fhswf/in/inf/java1/aufgabe4/Fill.java117
-rw-r--r--src/de/fhswf/in/inf/java1/tests/Tests.java31
3 files changed, 193 insertions, 0 deletions
diff --git a/src/de/fhswf/in/inf/java1/aufgabe1/HelloWorld.java b/src/de/fhswf/in/inf/java1/aufgabe1/HelloWorld.java
new file mode 100644
index 0000000..b80b714
--- /dev/null
+++ b/src/de/fhswf/in/inf/java1/aufgabe1/HelloWorld.java
@@ -0,0 +1,45 @@
+/**
+ *
+ */
+package de.fhswf.in.inf.java1.aufgabe1;
+
+/**
+ * Begrüßung der Sprache Java. Diese Klasse begrüßt die Sprache Java mit einem
+ * traditionellen "Hello World!".
+ *
+ * @author $Author: $
+ * @version $Revision: $, $Date: $ UTC
+ */
+public final class HelloWorld
+{
+ private HelloWorld()
+ {
+
+ }
+
+ /**
+ * Hauptmethode der Application. Begrüßung der Sprache Java. Diese Klasse
+ * begrüßt die Sprache Java mit einem traditionellen "Hello World!".
+ *
+ * @param args
+ * Übergabeparameter des Programms.
+ */
+ public static void main(String[] args)
+ {
+ System.out.println("Anzahl der Argumente: " + args.length);
+ if (args.length != 0)
+ {
+ System.out.print("Ihr Name ist:");
+ for (int i = 0; i < args.length; i++)
+ {
+ System.out.print(" " + args[i]);
+ }
+ System.out.println(".");
+ }
+ else
+ {
+ System.out.print("Kein Name vorhanden.");
+ }
+ }
+
+}
diff --git a/src/de/fhswf/in/inf/java1/aufgabe4/Fill.java b/src/de/fhswf/in/inf/java1/aufgabe4/Fill.java
new file mode 100644
index 0000000..20fdd84
--- /dev/null
+++ b/src/de/fhswf/in/inf/java1/aufgabe4/Fill.java
@@ -0,0 +1,117 @@
+/**
+ *
+ */
+package de.fhswf.in.inf.java1.aufgabe4;
+
+import java.util.Arrays;
+
+/**
+ * Tests the different methods to created a prefilled String.
+ *
+ * @author $Author: $
+ * @version $Revision: $, $Date: $ UTC
+ */
+public final class Fill
+{
+ private Fill()
+ {
+ }
+
+ /**
+ *
+ * Creates a string of given length filled with the given char.
+ *
+ * @param length
+ * Length of the returned String.
+ * @param c
+ * Char the String is filled with.
+ * @return Returns the generated String.
+ */
+ public static String createStringFilledWith(int length, char c)
+ {
+ // String that will be returned
+ String result = "";
+ for (int i = 0; i < length; i++)
+ {
+ // Every iteration, a new string is created.
+ result += c;
+ }
+ // Return the build string
+ return result;
+ }
+
+ /**
+ *
+ * Creates a string of given length filled with the given char.
+ *
+ * @param length
+ * Length of the returned String.
+ * @param c
+ * Char the String is filled with.
+ * @return Returns the generated String.
+ */
+ public static String createStringFilledWith2(int length, char c)
+ {
+ // charArray that will be returned
+ char[] result = new char[length];
+
+ Arrays.fill(result, c);
+
+ // Return the build string
+ return result.toString();
+ }
+
+ /**
+ *
+ * Creates a string of given length filled with the given char.
+ *
+ * @param length
+ * Length of the returned String.
+ * @param c
+ * Char the String is filled with.
+ * @return Returns the generated String.
+ */
+ public static String createStringFilledWith3(int length, char c)
+ {
+ // String that will be returned
+ StringBuilder result = new StringBuilder(length);
+ for (int i = 0; i < length; i++)
+ {
+ // Every iteration, a new string is created.
+ result.append(c);
+ }
+ // Return the build string
+ return result.toString();
+ }
+
+ /**
+ *
+ * Calls the function createStringFilledWith() and measures its runtime.
+ *
+ * @param args
+ * Console line arguments.
+ */
+ public static void main(String[] args)
+ {
+ final int anzDurchlaefe = 100000000;
+
+ long start;
+ start = System.currentTimeMillis(); // Gets current time in µs
+ Fill.createStringFilledWith(anzDurchlaefe, 'x'); // Function call
+ // Calculates the time runtime of creatStringFilledWith()
+ System.out.println("Elapsed time: "
+ + (System.currentTimeMillis() - start) + " ms");
+
+ start = System.currentTimeMillis(); // Gets current time in µs
+ Fill.createStringFilledWith2(anzDurchlaefe, 'x'); // Function call
+ // Calculates the time runtime of creatStringFilledWith2()
+ System.out.println("Elapsed time: "
+ + (System.currentTimeMillis() - start) + " ms");
+
+ start = System.currentTimeMillis(); // Gets current time in µs
+ Fill.createStringFilledWith3(anzDurchlaefe, 'x'); // Function call
+ // Calculates the time runtime of creatStringFilledWith3()
+ System.out.println("Elapsed time: "
+ + (System.currentTimeMillis() - start) + " ms");
+ }
+}
diff --git a/src/de/fhswf/in/inf/java1/tests/Tests.java b/src/de/fhswf/in/inf/java1/tests/Tests.java
new file mode 100644
index 0000000..ddf711e
--- /dev/null
+++ b/src/de/fhswf/in/inf/java1/tests/Tests.java
@@ -0,0 +1,31 @@
+package de.fhswf.in.inf.java1.tests;
+/**
+ *
+ * Test-Klasse für kleine Java-Snippets.
+ *
+ * @author $Author: $
+ * @version $Revision: $, $Date: $ UTC
+ */
+public final class Tests
+{
+ private Tests()
+ {
+
+ }
+
+ /**
+ *
+ * Haupt-Methode zum Testen von Java-Snippets.
+ *
+ * @param args
+ * Übergebene Argumente
+ */
+ public static void main(String[] args)
+ {
+ int a = -1;
+ System.out.println(Integer.toBinaryString(a));
+ System.out.println(Integer.toBinaryString(a >>> 1));
+
+ }
+
+}