Skip to content
Snippets Groups Projects
Commit b664ff62 authored by Radu-Andrei Coanda's avatar Radu-Andrei Coanda
Browse files

init

parents
No related branches found
No related tags found
No related merge requests found
Showing with 402 additions and 0 deletions
*.class
File added
File added
/**
* Programm zum Einlesen einer positiven Zahl und eines Worts, welches das Wort
* anschliessend so oft ausgibt, wie durch die Zahl festgelegt wurde.
*/
public class Multiecho {
public static void main(String[] args) {
// Einlesen der Zahl mit Ueberpruefung, dass die Zahl positiv ist:
int zahl = 0;
while (zahl < 1) {
zahl = SimpleIO.getInt("Bitte geben Sie eine positive Zahl ein");
}
// Einlesen des Wortes:
String wort = SimpleIO.getString("Bitte geben Sie ein Wort ein");
// Ausgabe des Wortes so oft wie durch die Zahl festgelegt wurde:
int i = 0;
String multi = "";
while (i < zahl) {
multi += wort;
i++;
}
SimpleIO.output(multi, "MultiEcho");
}
}
File added
public class BubbleSort {
public static int[] bubbleSort(int[] a) {
int tmp = -1;
for(int i = a.length - 1; i > 0; i--) {
for(int j = 0; j < i; j++) {
if(a[j] > a[j+1]) {
tmp = a[j];
a[j] = a[j+1];
a[j+1] = tmp;
}
}
}
return a;
}
public static void main(String args[]) {
int[] startArray = {23, 44, 2, 11, 20};
// Print unsorted Array
System.out.print("Unsortiertes Array: [");
for(int i = 0; i < startArray.length - 1; i++) {
System.out.print(startArray[i] + ", ");
}
System.out.print(startArray[startArray.length - 1] + "]\n");
int[] sortedArray = bubbleSort(startArray);
// Print sorted Array
System.out.print("Sortiertes Array: [");
for(int i = 0; i < sortedArray.length - 1; i++) {
System.out.print(sortedArray[i] + ", ");
}
System.out.print(sortedArray[sortedArray.length - 1] + "]\n");
}
}
\ No newline at end of file
public class Main {
public static void sammle ( Pilz [] wald , Mensch ... menschen ){
int i = 0;
for(Pilz pilz: wald) {
while(i < menschen.length && !menschen[i].hatPlatz()) {
i++;
}
if(i < menschen.length) {
menschen[i].korb[menschen[i].anzahl] = pilz;
menschen[i].anzahl++;
}
}
for(Mensch mensch: menschen) {
mensch.ausgabe();
}
}
public static void main ( String [] args ) {
Pilz steinpilz = new Pilz();
steinpilz.name = "Steinpilz";
Pilz champignon = new Pilz();
champignon.name = "Champignon";
Pilz pfifferling = new Pilz();
pfifferling.name = "Pfifferling";
Mensch bonnie = new Mensch();
bonnie.name = "Bonnie";
bonnie.korb = new Pilz[3];
Mensch clyde = new Mensch();
clyde.name = "Clyde";
clyde.korb = new Pilz[4];
Pilz [] wald = { steinpilz , champignon , champignon , pfifferling , steinpilz , pfifferling , champignon };
sammle ( wald , bonnie , clyde );
}
}
public class Mensch {
String name ;
Pilz [] korb ;
int anzahl = 0;
public boolean hatPlatz() {
boolean hatPlatz = false;
if( anzahl < korb.length) {
hatPlatz = true;
}
return hatPlatz;
}
public void ausgabe() {
System.out.println(name + ":");
for(Pilz pilz : korb) {
if(pilz != null) {
System.out.println(pilz.name);
}
}
}
}
public class Pilz {
String name;
}
\ No newline at end of file
File added
public class Test {
public static void main(String args[]) {
Toolbox tools = new Toolbox("Toolbox 1", 10);
System.out.println("-----------------------------------");
System.out.println(tools.getName() + " enthaelt " + tools.getCapacity() + " freie Plaetze.");
Tool t1 = Tool.Materials;
tools.addTool(t1);
Tool t2 = Tool.SimpleTool;
tools.addTool(t2);
Tool t3 = Tool.Materials;
tools.addTool(t3);
Tool t4 = Tool.PowerTool;
tools.addTool(t4);
Tool t5 = Tool.SimpleTool;
tools.addTool(t5);
Tool t6 = Tool.SimpleTool;
tools.addTool(t6);
Tool t7 = Tool.Materials;
tools.addTool(t7);
System.out.println("-----------------------------------");
System.out.println(tools.getName() + " enthaelt " + tools.getCapacity() + " freien Platz.");
tools.printAllTools();
Toolbox tools2 = new Toolbox("Toolbox 2", t1, t2, t3, t4, t5, t6, t7);
System.out.println("-----------------------------------");
System.out.println(tools2.getName() + " enthaelt " + tools2.getCapacity() + " freie Plaetze.");
tools2.printAllTools();
}
}
\ No newline at end of file
public enum Tool {
PowerTool, SimpleTool, Materials
}
\ No newline at end of file
disppublic class Toolbox {
private String name;
private int capacity;
private static final int PowerToolSize = 3;
private Tool[] tools;
public Toolbox(String name, int capacity) {
this.name = name;
this.capacity = capacity;
this.tools = new Tool[capacity];
}
public Toolbox(String name, Tool... tools) {
this.name = name;
this.capacity = 0;
this.tools = tools;
for(Tool tool: tools) {
if(tool == null) {
capacity += 1;
}
}
}
private boolean checkRoomForPowerTool(Wrapper w) {
int counter = 0;
if(this.tools == null || this.tools.length < Toolbox.PowerToolSize) {
return false;
}
for(int i = 0; i < this.tools.length; i++) {
if(this.tools[i] == null) {
counter += 1;
} else {
counter = 0;
}
if(counter == Toolbox.PowerToolSize) {
w.set(i - (Toolbox.PowerToolSize - 1));
return true;
}
}
return false;
}
public void addTool(Tool t) {
switch(t) {
case PowerTool:
Wrapper w = new Wrapper(0);
checkRoomForPowerTool(w);
for(int i = 0; i < Toolbox.PowerToolSize; ++i) {
this.tools[w.get() + i] = t;
}
this.capacity -= Toolbox.PowerToolSize;
break;
case SimpleTool:
for(int i = 0; i < this.tools.length; i++) {
if(this.tools[i] == null) {
this.tools[i] = t;
this.capacity -= 1;
break;
}
}
break;
case Materials:
for(int i = 0; i < this.tools.length; i++) {
if(this.tools[i] == null) {
this.tools[i] = t;
this.capacity -= 1;
break;
}
if(this.tools[i] == Tool.Materials) {
break;
}
}
break;
}
}
public void printAllTools() {
for(int i = 0; i < this.tools.length; i++) {
System.out.println("[" + i + "]: " + this.tools[i]);
}
}
// GETTERS & SETTERS
public int getCapacity() {
return this.capacity;
}
public String getName() {
return this.name;
}
public Tool getTool(int index) {
if(this.tools.length > index && index >= 0 && this.tools[index] != null) {
return this.tools[index];
}
return null;
}
public void setName(String name) {
this.name = name;
}
}
\ No newline at end of file
public class Wrapper {
private int i;
public Wrapper(int i) {
this.i = i;
}
public void set(int i) {
this.i = i;
}
public int get() {
return this.i;
}
}
File added
This diff is collapsed.
public class Drachenkurve {
private static void kurveR(Canvas c, int order) {
if(order <= 0) {
c.drawForward(10);
} else {
kurveR(c, order-1);
c.rotate(90);
kurveL(c, order-1);
}
}
public static void kurveL(Canvas c, int order) {
if(order <= 0) {
c.drawForward(10);
} else {
kurveR(c, order-1);
c.rotate(-90);
kurveL(c, order-1);
}
}
public static void main(String[] args) {
Canvas s = new Canvas();
s.rotate(180); // Rotiert die aktuelle Ausrichtung nach oben
kurveR(s, 3);
}
}
import java.util.Arrays;
public class Rekursion {
public static int arraySum(int[] a) {
int res = 0;
for (int i = 0; i < a.length; i++) {
res += a[i];
}
return res;
}
public static int recursiveArraySum(int[] a) {
if(a == null || a.length < 0) {
return 0;
}
if(a.length == 1) {
return a[0];
}
return a[a.length - 1] + recursiveArraySum( /*cutArray(a, 0, a.length - 2)*/ Arrays.copyOfRange(a, 0, a.length - 1) );
}
private static int[] cutArray(int[] a, int i, int j) {
// test
if(i > j && a.length < j) {
return null;
}
// new array
int[] b = new int[j - i + 1];
// fill
for(int q = 0; q < b.length; q++) {
b[q] = a[i + q];
}
return b;
}
public static void main(String[] args) {
int[] myArray = {1,2,3,4,5,6};
int arraySum = arraySum(myArray);
int recursiveArraySum = recursiveArraySum(myArray);
System.out.println(arraySum + " - " + recursiveArraySum);
}
}
\ No newline at end of file
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Java",
"type": "java",
"request": "launch",
"stopOnEntry": true,
"jdkPath": "${env:JAVA_HOME}/bin",
"cwd": "${fileDirname}",
"startupClass": "${fileBasenameNoExtension}",
"classpath": [
".",
"${fileDirname}"
],
"args": "42 75 12 33 141 5 0 442"
},
{
"name": "Java Console App",
"type": "java",
"request": "launch",
"stopOnEntry": true,
"jdkPath": "${env:JAVA_HOME}/bin",
"cwd": "${fileDirname}",
"startupClass": "${fileBasenameNoExtension}",
"classpath": [
".",
"${fileDirname}"
],
"externalConsole": true
}
]
}
\ No newline at end of file
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment