Smaller task & refactoring co2
This commit is contained in:
parent
e45d52037f
commit
1464df11cf
29 changed files with 683 additions and 0 deletions
7
Code/Steiner/arrayList/.vscode/settings.json
vendored
Normal file
7
Code/Steiner/arrayList/.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin",
|
||||
"java.project.referencedLibraries": [
|
||||
"lib/**/*.jar"
|
||||
]
|
||||
}
|
18
Code/Steiner/arrayList/README.md
Normal file
18
Code/Steiner/arrayList/README.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
BIN
Code/Steiner/arrayList/bin/App.class
Normal file
BIN
Code/Steiner/arrayList/bin/App.class
Normal file
Binary file not shown.
BIN
Code/Steiner/arrayList/src/App.class
Normal file
BIN
Code/Steiner/arrayList/src/App.class
Normal file
Binary file not shown.
71
Code/Steiner/arrayList/src/App.java
Normal file
71
Code/Steiner/arrayList/src/App.java
Normal file
|
@ -0,0 +1,71 @@
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
int[] array = { 0, 1, 2, 3, 4, 5, 4, -3, -2, 0 };
|
||||
ArrayList<Integer> list = new ArrayList<>();
|
||||
|
||||
initializeListFromArray(array, list);
|
||||
printList("ArrayList vor Modifikationen:", list);
|
||||
|
||||
addValues(list, 10, -5);
|
||||
removeElementAt(list, 1);
|
||||
printList("ArrayList nach Modifikationen:", list);
|
||||
|
||||
sortList(list);
|
||||
printList("ArrayList nach Sortierung:", list);
|
||||
|
||||
shuffleList(list);
|
||||
printList("ArrayList nach dem Mischen:", list);
|
||||
|
||||
printMinMaxValues(list);
|
||||
}
|
||||
|
||||
// Initialisiert die ArrayList mit Werten aus dem Array
|
||||
private static void initializeListFromArray(int[] array, ArrayList<Integer> list) {
|
||||
for (int num : array) {
|
||||
list.add(num);
|
||||
}
|
||||
}
|
||||
|
||||
// Fügt der ArrayList zwei Werte hinzu
|
||||
private static void addValues(ArrayList<Integer> list, int value1, int value2) {
|
||||
list.add(value1);
|
||||
list.add(value2);
|
||||
}
|
||||
|
||||
// Entfernt das Element an einer bestimmten Position
|
||||
private static void removeElementAt(ArrayList<Integer> list, int index) {
|
||||
if (index >= 0 && index < list.size()) {
|
||||
list.remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
// Gibt den Inhalt der ArrayList aus
|
||||
private static void printList(String message, ArrayList<Integer> list) {
|
||||
System.out.println(message);
|
||||
for (int num : list) {
|
||||
System.out.print(num + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
// Sortiert die ArrayList
|
||||
private static void sortList(ArrayList<Integer> list) {
|
||||
Collections.sort(list);
|
||||
}
|
||||
|
||||
// Mischt die ArrayList
|
||||
private static void shuffleList(ArrayList<Integer> list) {
|
||||
Collections.shuffle(list);
|
||||
}
|
||||
|
||||
// Gibt den maximalen und minimalen Wert der ArrayList aus
|
||||
private static void printMinMaxValues(ArrayList<Integer> list) {
|
||||
int max = Collections.max(list);
|
||||
int min = Collections.min(list);
|
||||
System.out.println("Maximaler Wert: " + max);
|
||||
System.out.println("Minimaler Wert: " + min);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue