diff --git a/Aufgaben/PTP_1/J05A2.java b/Aufgaben/PTP_1/J05A2.java new file mode 100644 index 0000000..21598fd --- /dev/null +++ b/Aufgaben/PTP_1/J05A2.java @@ -0,0 +1,36 @@ +import java.util.Arrays; +public class J05A2 { + public static void main(String args[]){ + int zahlen[] = {13, 9, 67, 42, 101, 99, 97, 112, 83, 5, 78}; + + + + // a) + for (int i = 0; i < zahlen.length; i++) { + System.out.println("Zahl Nr. " + (i+1) + " lautet " + zahlen[i]); + } + + for (int zahl: zahlen ) { + System.out.println(zahl); + } + + // b) + for (int i = 0; i < zahlen.length; i++) { + if (i < zahlen.length - 1) { + System.out.print(zahlen[i] + " - "); + } else { + System.out.println(zahlen[i]); + } + } + + // c) + Arrays.sort(zahlen); + for (int zahl: zahlen ) { + System.out.println(zahl); + } + + System.out.println("Kleinstes Element: " + zahlen[0]); + System.out.println("Größtes Element: " + zahlen[zahlen.length - 1]); + + } +} \ No newline at end of file diff --git a/Aufgaben/PTP_1/Kraftstoffverbrauch.java b/Aufgaben/PTP_1/Kraftstoffverbrauch.java new file mode 100644 index 0000000..6923bd7 --- /dev/null +++ b/Aufgaben/PTP_1/Kraftstoffverbrauch.java @@ -0,0 +1,13 @@ +public class Kraftstoffverbrauch { + public static void main(String args[]){ + double gefahreneKm = 437; + double verbrauchterKraftstoff = 28.9; + + double verbrauch100Km = (verbrauchterKraftstoff / gefahreneKm) * 100; + + System.out.println("Gefahrene KM: " + gefahreneKm); + System.out.println("Verbrauchter Kraftstoff: " + verbrauchterKraftstoff +" Liter"); + System.out.println("Verbrauch je 100km: " + verbrauch100Km + " Liter je 100Km"); + + } +} \ No newline at end of file diff --git a/Aufgaben/PTP_1/Lottozahlen.java b/Aufgaben/PTP_1/Lottozahlen.java new file mode 100644 index 0000000..5137994 --- /dev/null +++ b/Aufgaben/PTP_1/Lottozahlen.java @@ -0,0 +1,60 @@ +import java.util.Arrays; +import java.util.Scanner; + +public class Lottozahlen { + public static void main(String args[]){ + int lottozahlen[] = {17, 9, 39, 23, 41, 6}; + //Scanner eingabe = new Scanner(System.in); + + /* + int lottozahlen[] = new int[6]; + lottozahlen[0] = eingabe.nextInt(); + lottozahlen[1] = eingabe.nextInt(); + lottozahlen[2] = eingabe.nextInt(); + lottozahlen[3] = eingabe.nextInt(); + lottozahlen[4] = eingabe.nextInt(); + lottozahlen[5] = eingabe.nextInt(); + */ + + System.out.println("Die heutigen Lottozahlen sind " + lottozahlen); + System.out.println("Es sind " + lottozahlen.length + " Lottozahlen gezogen worden."); + System.out.println("Die erste Lottozahl lautet: " + lottozahlen[0]); + System.out.println("Die zweite Lottozahl lautet: " + lottozahlen[1]); + System.out.println("Die dritte Lottozahl lautet: " + lottozahlen[2]); + System.out.println("Die vierte Lottozahl lautet: " + lottozahlen[3]); + System.out.println("Die fünfte Lottozahl lautet: " + lottozahlen[4]); + System.out.println("Die sechste Lottozahl lautet: " + lottozahlen[5]); + + System.out.println("- - - - - - - - - - - - - - - - - - -"); + + //lottozahlen[3] = 32; + System.out.println("Die vierte Lottozahl lautet: " + lottozahlen[3]); + + System.out.println("- - - - - - - - - - - - - - - - - - -"); + + for (int i = 0; i < lottozahlen.length; i++) { + System.out.println("Lottozahl Nr. " + (i + 1) + " lautet " + lottozahlen[i]); + } + + System.out.println("- - - - - - - - - - - - - - - - - - -"); + + for (int zahl: lottozahlen) { + System.out.println("Die aktuelle Lottozahl lautet: " + zahl); + } + + System.out.println("- - - - - - - - - - - - - - - - - - -"); + + Arrays.sort(lottozahlen); + + System.out.println("Die erste Lottozahl lautet: " + lottozahlen[0]); + System.out.println("Die zweite Lottozahl lautet: " + lottozahlen[1]); + System.out.println("Die dritte Lottozahl lautet: " + lottozahlen[2]); + System.out.println("Die vierte Lottozahl lautet: " + lottozahlen[3]); + System.out.println("Die fünfte Lottozahl lautet: " + lottozahlen[4]); + System.out.println("Die sechste Lottozahl lautet: " + lottozahlen[5]); + + System.out.println("- - - - - - - - - - - - - - - - - - -"); + + System.out.println("Die heutigen Lottozahlen sind: " + Arrays.toString(lottozahlen)); + } +} \ No newline at end of file diff --git a/Aufgaben/PTP_1/MeinErstesProgramm.java b/Aufgaben/PTP_1/MeinErstesProgramm.java new file mode 100644 index 0000000..146b3bd --- /dev/null +++ b/Aufgaben/PTP_1/MeinErstesProgramm.java @@ -0,0 +1,5 @@ +public class MeinErstesProgramm{ + public static void main(String args[]){ + System.out.println("Hallo Welt!"); + } +} \ No newline at end of file diff --git a/Aufgaben/PTP_1/lottoArray.java b/Aufgaben/PTP_1/lottoArray.java new file mode 100644 index 0000000..e075e64 --- /dev/null +++ b/Aufgaben/PTP_1/lottoArray.java @@ -0,0 +1,10 @@ +import java.util.Arrays; +public class lottoArray{ + public static void main(String args[]){ + int lottozahlen[] = {17, 9, 39, 23, 41, 6}; + System.out.println("Anzahl Elemente im Array: " + lottozahlen.length); + System.out.println("Komplettes Array: " + Arrays.toString(lottozahlen)); + Arrays.sort(lottozahlen); + System.out.println("Komplettes Array: " + Arrays.toString(lottozahlen)); + } +} \ No newline at end of file