Add Java-Kompendium book

This commit is contained in:
2025-11-24 23:20:51 +01:00
parent f3b3d4b1a2
commit a680b83e47
8 changed files with 122 additions and 0 deletions

1
Java-Kompendium/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.class

View File

@@ -0,0 +1,11 @@
// OOP sucks.
public class HalloWelt {
/**
* Java sucks.
*
* @param args Command line arguments.
*/
public static void main(String[] args) {
System.out.print("Java sucks\n");
}
}

View File

@@ -0,0 +1,10 @@
public class Task1 {
public static void main(String[] args) {
int x;
short y = 8;
long z;
x = y;
z = y;
}
}

View File

@@ -0,0 +1,15 @@
import java.io.*;
public class Task2 {
public static void main(String[] args) throws IOException {
System.out.print("Geben Sie eine Zahl ein: ");
var inputStream = new InputStreamReader(System.in);
var bufferedStream = new BufferedReader(inputStream);
String variable = bufferedStream.readLine();
int converted = Integer.parseInt(variable);
System.out.println("Der doppelte Wert ist: " + (converted * 2));
}
}

View File

@@ -0,0 +1,37 @@
import java.util.*;
public class Task1 {
public static void main(String[] args) {
ArrayList<String> workers = new ArrayList<>(6);
workers.add("Maximilian Mayer");
workers.add("Emil Faber");
workers.add("Anna Müller");
workers.add("Sebastian Waller");
workers.add("Oliver Stilz");
workers.add("Peter Huber");
print(workers);
System.out.println();
System.out.print("Der erste Name: ");
System.out.println(workers.get(0));
System.out.print("Der letzte Name: ");
System.out.println(workers.get(workers.size() - 1));
workers.set(3, "Frank Starke");
System.out.println();
print(workers);
}
public static void print(ArrayList<String> list) {
System.out.println(list.get(0));
System.out.println(list.get(1));
System.out.println(list.get(2));
System.out.println(list.get(3));
System.out.println(list.get(4));
System.out.println(list.get(5));
}
}

View File

@@ -0,0 +1,15 @@
import java.util.*;
import java.io.*;
public class Task2 {
public static void main(String[] args) throws IOException {
var workers = new ArrayList<String>();
var stream = new InputStreamReader(System.in);
var bufferedStream = new BufferedReader(stream);
for (int i = 0; i < 5; ++i) {
workers.add(bufferedStream.readLine());
}
System.out.println("Folgende Mitarbeiter haben sie angegeben: " + workers);
}
}

View File

@@ -0,0 +1,29 @@
import java.util.*;
public class Task3 {
public static void main(String[] args) {
var javaList = new HashSet<String>(3);
var pythonList = new HashSet<String>(3);
var commonList = new HashSet<String>();
var differenceSet = new HashSet<String>();
javaList.add("Maximilian Mayer");
javaList.add("Emil Faber");
javaList.add("Anna Müller");
pythonList.add("Anna Müller");
pythonList.add("Sebastian Waller");
pythonList.add("Oliver Stilz");
commonList.addAll(javaList);
commonList.addAll(pythonList);
differenceSet.addAll(javaList);
differenceSet.retainAll(pythonList);
System.out.println("Java-Kurs: " + javaList);
System.out.println("Python-Kurs: " + pythonList);
System.out.println("Alle Teilnehmer: " + commonList);
System.out.println("Beide Kurse: " + differenceSet);
}
}